Jump to content

rounding massive numbers


taith

Recommended Posts

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?

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
?>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.