|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2000-08-09 02:34 UTC] hholzgra@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 17 13:00:01 2025 UTC |
When adding several numbers it appears that they should add to zero. Unfortunatly they dont. For example: <? // This is a very simple representation of the problem $ary[] = 54493.08; $ary[] = 18900.58; $ary[] = 45819.39; $ary[] = 22901.79; $ary[] = 13342.42; $ary[] = -127799; $ary[] = 1755; $ary[] = -29413.01; $ary[] = -0.25; $ary[] = 0; while(list($key,$val) = each($ary)){ $total = $val + $total; echo "Value: $val Total: $total<br>\n"; } ?> The running total returns; Value: 54493.08 Total: 54493.08 Value: 18900.58 Total: 73393.66 Value: 45819.39 Total: 119213.05 Value: 22901.79 Total: 142114.84 Value: 13342.42 Total: 155457.26 Value: -127799 Total: 27658.26 Value: 1755 Total: 29413.26 Value: -29413.01 Total: 0.25000000001091 Value: -0.25 Total: 1.0913936421275E-011 Value: 0 Total: 1.0913936421275E-011 So you can see that 29413.26 + -29413.01 doesnt equal 0.25 as it should. mn