For very large numbers php converts the number in exponential form. How can i convert it back to decimal form.
e.g.
<?php
$input =50;
$res = pow($input,$input);
echo $res;
?>
Here how can i have output in decimal format.
Expo to decimal format
Moderator: General Moderators
Re: Expo to decimal format
Maybe if you convert it to a string. You should be able to cast it like:
Code: Select all
$res = (string)pow($input,$input);Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Expo to decimal format
Code: Select all
printf('%f', $res);
// or
$res = sprintf('%f', pow($input, $input));mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
Re: Expo to decimal format
http://www.php.net/manual/en/refs.math.php
The first two extensions help a lot with arbitrarily large numbers if I remember correctly. If anyone knows otherwise speak up for OP benefit and mine in the future.
The first two extensions help a lot with arbitrarily large numbers if I remember correctly. If anyone knows otherwise speak up for OP benefit and mine in the future.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Expo to decimal format
Now you just have $res of type string containing 8.881784197E+84 instead of a double.pickle wrote:Maybe if you convert it to a string. You should be able to cast it like:
Code: Select all
$res = (string)pow($input,$input);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.