Page 1 of 1

Expo to decimal format

Posted: Thu Jan 14, 2010 7:42 am
by rohitmanglik
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.

Re: Expo to decimal format

Posted: Thu Jan 14, 2010 10:33 am
by pickle
Maybe if you convert it to a string. You should be able to cast it like:

Code: Select all

$res = (string)pow($input,$input);

Re: Expo to decimal format

Posted: Thu Jan 14, 2010 10:34 am
by AbraCadaver

Code: Select all

printf('%f', $res);
 
// or
 
$res = sprintf('%f', pow($input, $input));

Re: Expo to decimal format

Posted: Thu Jan 14, 2010 10:36 am
by Charles256
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. :)

Re: Expo to decimal format

Posted: Thu Jan 14, 2010 10:41 am
by AbraCadaver
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);
Now you just have $res of type string containing 8.881784197E+84 instead of a double.