Jump to content


Photo

Decimal Adding Error


  • Please log in to reply
1 reply to this topic

#1 atbjk

atbjk
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 28 June 2006 - 09:35 AM

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

#2 Brandon Jaeger

Brandon Jaeger
  • Members
  • PipPipPip
  • Advanced Member
  • 155 posts
  • LocationPA
  • Age:25

Posted 28 June 2006 - 10:43 AM

That's kinda how math works. Though, I'm not sure how to add that extra 0 in the ten thousandths position in your situation.
PHP is my friend (=




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users