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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.