Asked  10 Months ago    Answers:  5   Viewed   1 times

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.



What about a simple cast to a float value ?

$string = "7.2769482308e+01";
$float  = (float) $string;
Saturday, July 31, 2021

You need a better math extension like BC Math, GMP... to handle the more precise precision.

Limitation of floating number & integer

Thursday, April 1, 2021

Here's what worked best for me when trying to script this (in case anyone else comes across this like I did):

$ pecl -d php_suffix=5.6 install <package>
$ pecl uninstall -r <package>

$ pecl -d php_suffix=7.0 install <package>
$ pecl uninstall -r <package>

$ pecl -d php_suffix=7.1 install <package>
$ pecl uninstall -r <package>

The -d php_suffix=<version> piece allows you to set config values at run time vs pre-setting them with pecl config-set. The uninstall -r bit does not actually uninstall it (from the docs):

vagrant@homestead:~$ pecl help uninstall
pecl uninstall [options] [channel/]<package> ...
Uninstalls one or more PEAR packages.  More than one package may be
specified at once.  Prefix with channel name to uninstall from a
channel not in your default channel (

  -r, --register-only
        do not remove files, only register the packages as not installed

The uninstall line is necessary otherwise installing it will remove any previously installed version, even if it was for a different PHP version (ex: Installing an extension for PHP 7.0 would remove the 5.6 version if the package was still registered as installed).

Thursday, April 1, 2021

Provide correct output for this so that we test and throw few more sample data.

Try this,

SELECT CONVERT(decimal(18,8), CAST('5E-05' AS FLOAT))
Wednesday, December 1, 2021

Never used any of those, but they look interesting..

Take a look at Gearman as well.. more overhead in systems like these but you get other cool stuff :) Guess it depends on your needs ..

Friday, December 24, 2021
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :