Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert exponential number presented as string to a decimal

Tags:

php

Let's suppose I have a string that contains "7.2769482308e+01" (this number came from 3rd party software, I cannot control the format).

What is the cheapest way to convert it into decimal 72.769482308?

The only solution I can think of is to split decimal + exponential part and use multiplication. But may be there some built it function to do the same?

NOTE: Guys, yes, I've read Convert exponential to a whole number in PHP and Convert exponential number to decimal in php. And that questions are irrelevant, since they already have a number, but I have a string.

like image 884
zerkms Avatar asked Mar 17 '11 14:03

zerkms


People also ask

How do you convert an exponential number to numeric?

The Scientific format displays a number in exponential notation, replacing part of the number with E+n, where E (which stands for Exponent) multiplies the preceding number by 10 to the nth power. For example, a 2-decimal Scientific format displays 12345678901 as 1.23E+10, which is 1.23 times 10 to the 10th power."

How do I convert an exponential number to a csv file?

If you are using a CSV file, convert any in exponential "E" number format to a standard number in the CSV file before importing it. On the transformation map, for each field map from an exponential field, set the source [script] as: answer = Number(source. <field containing the exponential>.


1 Answers

What about a simple cast to a float value ?

$string = "7.2769482308e+01";
$float  = (float) $string;
like image 185
hsz Avatar answered Sep 27 '22 22:09

hsz