note 7219 deleted from function.round by jeroen

From: Date: Sat, 01 Sep 2001 12:39:53 +0000
Subject: note 7219 deleted from function.round by jeroen
Groups: php.notes 
Request: Send a blank email to php-notes+get-17499@lists.php.net to get a copy of this message
A note on an old thread about rounding... <br><br>Proper rounding is to round 'even' on .5 (ie 1.5 to 2 and 2.5 to 2). The reason for this is actually scientific (I haven't heard of the banking application, altho it does lend itself as well): when you make calculations you have to keep your significant figures. If your data is accurate to 2 decimal places you must round off to exactly two places. If you always rounded that .5 up (or down), then you round one way 5 out of 9 times and thus change the distribution of random data. The fix is to round up half of the time and down half of the time. This could be accomplished by 'rounding odd', but the standardized way is to always 'round even'.<br><br>Unfortunately this isn't what they taught us in 1st grade, so most people think that you always round up. If you still want to, you'll have to either add a small fraction and risk inaccurate calculations (1.49 + 0.01 rounds to 2) or call ceil() on your number before rounding.

« previous php.notes (#17499) next »