Bug #68589 [NEW]: sprintf decimal number formatting
| From: | vardhane at gmail dot com | Date: | Thu, 11 Dec 2014 06:41:33 +0000 |
| Subject: | Bug #68589 [NEW]: sprintf decimal number formatting | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-189011@lists.php.net to get a copy of this message | ||
From: vardhane at gmail dot com
Operating system:
PHP version: 5.6.3
Package: Strings related
Bug Type: Bug
Bug description:sprintf decimal number formatting
Description:
------------
---
From manual page: http://www.php.net/function.sprintf
---
<?php
$format = '%10.2f';
$args = 103790.3550;
$result = sprintf ($format, $args);
?>
Test script:
---------------
Hello Team,
When I am using sprintf to format my decimal 2 decimal places it is
giving weird results. I tried the following,
0.405 = 0.40
0.415 = 0.41
0.425 = 0.43
0.435 = 0.43
0.445 = 0.44
0.455 = 0.46
0.465 = 0.46
0.475 = 0.48
0.485 = 0.49
0.495 = 0.49
Please Help!
Expected result:
----------------
103790.36
Actual result:
--------------
103790.35
--
Edit bug report at https://bugs.php.net/bug.php?id=68589&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68589&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68589&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68589&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=68589&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=68589&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=68589&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=68589&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=68589&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=68589&r=support
Expected behavior: https://bugs.php.net/fix.php?id=68589&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=68589&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=68589&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=68589&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68589&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=68589&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=68589&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=68589&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68589&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=68589&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=68589&r=mysqlcfg