taith Posted April 19, 2007 Share Posted April 19, 2007 anyone know an easy way to round massive numbers? for example... echo round(78906898968967.432324); outputs "7.8906898969E+013" which is so totally unhelpful... Quote Link to comment Share on other sites More sharing options...
per1os Posted April 19, 2007 Share Posted April 19, 2007 http://us.php.net/round <?php echo round(78906898968967.432324, 2); ?> See also: http://us.php.net/manual/en/function.ceil.php http://us.php.net/manual/en/function.floor.php Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 19, 2007 Share Posted April 19, 2007 echo number_format(78906898968967.432324, 0); Quote Link to comment Share on other sites More sharing options...
taith Posted April 19, 2007 Author Share Posted April 19, 2007 yes... but the scientific notation is not turnoffable... echo round(78906898968967.432324, 2); outputs "7.8906898969E+013" i need "78906898968967.43" Quote Link to comment Share on other sites More sharing options...
taith Posted April 19, 2007 Author Share Posted April 19, 2007 i've made this... it works... sorta... function realround($string,$decimal=2){ if(!is_numeric($string)) return $string; $string=explode(".",$string); if(count($string)==1) return $string[0]; $string[1]='1.'.$string[1]; $string[1]=round($string[1],$decimal); $string[1]=substr($string[1],2); return implode(".",$string); } any better suggestions? Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 20, 2007 Share Posted April 20, 2007 Um, did you try my suggestion of using number_format()? It worked for me. Since you need two decimal places use this: echo number_format(78906898968967.432324, 2); Quote Link to comment Share on other sites More sharing options...
taith Posted April 20, 2007 Author Share Posted April 20, 2007 yes... but that adds ,'s in... i need realnumbers... true, i can remove them easy enough... question comes in... why does round() give scientific notation by default? shouldnt that be a seperate option? Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 20, 2007 Share Posted April 20, 2007 C'mon partner, don't expect us to do ALL the work for you. If you had taken just 30 seconds to look at the manual for number_format() you would have seen that you can customize the thousands seperator (which also means you can remove it). http://us2.php.net/manual/en/function.number-format.php <?php echo number_format(78906898968967.432324, 2, '.', '') // Output would be 78906898968967.44 ?> Quote Link to comment Share on other sites More sharing options...
taith Posted April 20, 2007 Author Share Posted April 20, 2007 bah... too simple... i still say we should contact php mainframe programmers and have the scientific notation added as an option only... in fact... i think i will :-) Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 20, 2007 Share Posted April 20, 2007 Uh...no. Round is rounding a number and is returning the value of that number. It is returning the value in the most efficient method. It is not intended for format a number. Unless you are presenting a number on the screen it doesn't matter what format it uses internally. That is where number_format comes in. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.