PHP math with long decimals -
i'm trying math large decimals. works fine:
<?php $math = 99 + 0.0001; echo $math; ?> output: 99.0001
however, when try add decimals more 12 decimal places, not receive expected output:
<?php $math = 99 + 0.0000000000001; echo $math; ?> output: 99
how can make if add decimal has more 12 decimal places, result still have exact answer without rounding? example:
<?php $math = 99 + 0.0000000000001; echo $math; ?> output: 99.0000000000001
quick google search yielded this.
floating point numbers have limited precision. although depends on system, php typically uses ieee 754 double precision format, give maximum relative error due rounding in order of 1.11e-16.
the page linked has lots of helpful info regarding floating point numbers in php links libraries can work arbitrary precision floating point numbers. useful depending on needs.
edit: also, mark baker said in comment, may need specify precision of number want print in printf() format string. check this page out , @ number 5.
Comments
Post a Comment