Jump to content

Decimal Adding Error


atbjk

Recommended Posts

ok im trying to add some decimals together but when i add a decimal that equals a number like 10 or 20 it does not print the trailing zero. I not trying to echo this data, it does it in memory im using echo to show you, i dont know why it does this any help would be greatful

Reproduce code:
---------------
for ($i=0; $i<23; $i++) {
echo 0.0001+($i*0.0001).'<br>';
}

Expected result:
----------------
0.0001
0.0002
0.0003
0.0004
0.0005
0.0006
0.0007
0.0008
0.0009
0.0010
0.0011
0.0012
0.0013
0.0014
0.0015
0.0016
0.0017
0.0018
0.0019
0.0020
0.0021
0.0022
0.0023

Actual result:
--------------
0.0001
0.0002
0.0003
0.0004
0.0005
0.0006
0.0007
0.0008
0.0009
0.001
0.0011
0.0012
0.0013
0.0014
0.0015
0.0016
0.0017
0.0018
0.0019
0.002
0.0021
0.0022
0.0023
Link to comment
https://forums.phpfreaks.com/topic/13088-decimal-adding-error/
Share on other sites

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.