473,413 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

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 8041
This is what I use to convert float|real|double 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*****@guestwho.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|double 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
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...
1
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,...
1
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...
0
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...
9
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 ...
2
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...
2
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...
3
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),...
2
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. ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
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...

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.