|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-01-21 16:04 UTC] nicolas dot giraud at actiane dot com
Description: ------------ The number_format function don't give the good result with good format, maybe because of cast in float that kills precision. Test script: --------------- <?php $number = '123456789012345678901234567890'; $formatted = number_format($number, 2, '.', ' '); echo $formatted; ?> Expected result: ---------------- 123 456 789 012 345 678 901 234 567 890.00 Actual result: -------------- 123 456 789 012 345 660 285 533 552 640.00 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 17 07:00:01 2025 UTC |
Not much we can do about that. number_format() takes a float and you are overflowing a float with your huge value. Since you already have it as a string, you could just throw a regex at it. Something like: preg_replace("/(?<=\d)(?=(\d{3})+(?!\d))/",",",$number);