|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-10-09 07:54 UTC] msajko at yahoo dot com
Description: ------------ round(555.305,1) = 555.3 round(555.305,2) = 555.3 !!!? (555.31 is correct) round(555.305,3) = 555.305 problem appears in Windows binary, on debian binary it works just fine Reproduce code: --------------- echo round(555.305,2) ."\n"; echo (round(555.305,2)*1)."\n"; Expected result: ---------------- 555.31 555.31 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 20 05:00:01 2025 UTC |
I can't belive that I will have to use my round functions in every new aplication I made? :-( function roundit($val,$precision=0){ $num=$val+(('0.'.str_repeat('0',$precision).'5')*1); $a=explode(".",$num); return ($a[0].'.'.substr($a[1],0,$precision))*1; } function numberformat($number,$decimals='2',$dec_point='.',$thousands_sep=','){ $number=roundit($number,$decimals); return number_format($number,$decimals,$dec_point,$thousands_sep); }