|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-08-28 21:36 UTC] jani@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Nov 30 12:00:01 2025 UTC |
Description: ------------ When rounding (implicitly) with sprintf, halfway values are rounded using a "banker's" algorithm instead of performing the way a call to round() would. This seems inconsistent and counterintuitive for no particular reason. Thanks! Reproduce code: --------------- print sprintf("%2.2f", 0.015)."<br/>"; print sprintf("%2.2f", 0.025)."<br/>"; print sprintf("%2.2f", 0.035)."<br/>"; print sprintf("%2.2f", 0.045)."<br/>"; print "<br/>"; print round(0.015, 2)."<br/>"; print round(0.025, 2)."<br/>"; print round(0.035, 2)."<br/>"; print round(0.045, 2)."<br/>"; Expected result: ---------------- 0.02 0.03 0.04 0.05 0.02 0.03 0.04 0.05 Actual result: -------------- 0.01 0.03 0.04 0.04 0.02 0.03 0.04 0.05