Hello, Is there any PHP function that can limit the decimal digits? If I got a double number like 5.123456, too many decimal digits, how to limit it to 5.12? Thanks!
function chrisarms($value) { if(!ereg(".",$value) { return($value); } $parts = explode(".",$value); $afterpoint = substr($parts[1],0,2); $everything = $parts[0].".".$afterpoint; return($everything); }
number_format() being the easy way 🙂
<? $number = 5.123456; $format_num = number_format($number, 2); ?>
thank u all!
There again,
$conversion=92.663532 $formatted = sprintf("%01.2f", $conversion); echo $formatted;
Could also be anothe way of putting it.