Expo to decimal format

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
rohitmanglik
Forum Newbie
Posts: 1
Joined: Thu Jan 14, 2010 7:37 am

Expo to decimal format

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Expo to decimal format

Post 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);
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Expo to decimal format

Post by AbraCadaver »

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

Post 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. :)
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Expo to decimal format

Post 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.
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.
Post Reply