473,790 Members | 3,185 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Converting scientific notation

Hi,

I have a script that generates numbers beyond the range of it, and so it's
throwing them out as scientfic notation (e.g. 5E+10 instead of
50,000,000,000) . The only way I've found of avoiding this is by using bc*()
functions in place of normal operators (e.g. bcmul() instead of '*').
Surely there's a way to simply convert a number in scientific notation into
a normal integer ?

Regards,
Chris
Jul 17 '05 #1
2 8069
This is what I use to convert float|real|doub le values into display format:

$float = sprintf('%f', $fieldvalue);
$integer = sprintf('%d', $fieldvalue);
if ($float == $integer) {
// this is a whole number, so remove all decimals
$output = $integer;
} else {
// remove trailing zeroes from the decimal portion
$output = rtrim($float,'0 ');
} // if

HTH.

--
Tony Marston

http://www.tonymarston.net

"Skeleton Man" <in*****@guestw ho.com> wrote in message
news:ZZ******** ******@news-server.bigpond. net.au...
Hi,

I have a script that generates numbers beyond the range of it, and so it's
throwing them out as scientfic notation (e.g. 5E+10 instead of
50,000,000,000) . The only way I've found of avoiding this is by using
bc*()
functions in place of normal operators (e.g. bcmul() instead of '*').
Surely there's a way to simply convert a number in scientific notation
into
a normal integer ?

Regards,
Chris

Jul 17 '05 #2
>This is what I use to convert float|real|doub le values into display format:
$float = sprintf('%f', $fieldvalue);
$integer = sprintf('%d', $fieldvalue);
if ($float == $integer) {
// this is a whole number, so remove all decimals
$output = $integer;
} else {
// remove trailing zeroes from the decimal portion
$output = rtrim($float,'0 ');
} // if


That works brilliantly, thankyou !

Regards,
Chris
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
8727
by: Woodster | last post by:
I am using the std::setprecision function to format variables of type double in a string however I am unsure how to stop this appearing in scientific notation. For example std::stringstream buffer; buffer << setprecision(1) << 40.0 << "° C";
1
8866
by: Nick | last post by:
Well, the project I am working on has now come to a screeching halt! I have been developing a program that heavily utilizes ADO.NET record sets. To generate reports, I convert the recordset to XML, and then apply an XSLT to transform the XML into HTML. This works great (or did) until today. I just found out that the "number-format" command in XSLT can't handle scientific notation! So when I try to format these numbers I just get "NaN" on...
1
11664
by: Kent Lewandowski | last post by:
Hi, I saw this post from 3 years ago regarding converting DOUBLE values to CHAR in ibm DB2. Now I'm having the same problem. No real solution was posted to that old thread. Has anyone got more information how I avoid the scientific notation when I use the CHAR() function to convert a DOUBLE or FLOAT ? What I want is "MagicFunction" in the following pseudocode: myVarchar = MagicFunction(123.0003);
0
1712
by: Greg | last post by:
I am working on an application that requires working with numbers in scientific notation. I am using SqlServer as the database and I have created strongly typed data adapters and datasets. The numbers are defined as numeric in the SqlServer Database and are bound to text boxes in the app. In the dataset xml these numbers are defined as decimal. I am using the binding method Format to display the data in scientific notation and Parse to...
9
6671
by: Joe Attardi | last post by:
Hi all, Math is not my strongest area so forgive me if I use some of the wrong terminology. It seems that scientific notation is immune to rounding errors. For example: (4.98 * 100) + 5.51 // returns 503.51000000000005, rounding error! 4.98e2 + 5.51 // returns 503.51, correct!
2
2767
by: rSmoke | last post by:
I have a DataSet that contains a table with about 6 columns of high accuracy decimal values. When I try to write out the DataSet using the WriteXML() function the XML is written fine, but the decimal values are written out in scientific notation ("9.984348392E+08"). This wouldn't be a problem except when I try to READ the XML file back into a DataSet I keep getting a System.FormatException saying "Input string was not in a correct format."...
2
7033
by: Greg | last post by:
I am working on an application that requires working with numbers in scientific notation. I am using SqlServer as the database and I have created strongly typed data adapters and datasets. The numbers are defined as numeric in the SqlServer Database and are bound to text boxes in the app. In the dataset's xml these numbers are defined as decimal. I am using the binding method Format to display the data in scientific notation and Parse to...
3
2407
by: nvx | last post by:
Hi, I'm looking for a simple way to convert a Double to a String exactly the .ToString() does, except these two differences: - the number of decimals is given (rounding is applied if necessary), and - trailing zeroes are kept. This means I need it to be converted using the scientific notation if the number is greater than a certain value etc., not just a simple "this number of digits (or more if needed) before the decimal point
2
2736
by: jasonwthompson | last post by:
I'm converting some old C code to C++. Although I'm not concerned about converting every C item to C++ I'm in a situation in which using an ostringstream makes more sense than using sprintf. Here's my problem: In sprintf, one could use the %g symbol to indicate that I either wanted scientific notation or a simple floating point, whichever is smaller. Is there a way to do that using an ostringstream? Basically, what is the...
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9512
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10201
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10147
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6770
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5424
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3709
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2910
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.