ID:               42276
 Updated by:       [EMAIL PROTECTED]
 Reported By:      eb1024 at gmail dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Strings related
 Operating System: Windows XP / Fedora / (Others?)
 PHP Version:      4.4.7
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

That's because number_format takes a float, and not a string. And
floats have a maximum precision.


Previous Comments:
------------------------------------------------------------------------

[2007-08-12 08:10:52] missingno at ifrance dot com

As per the doc, number_format() is meant to format floating point
values (see http://php.net/number_format), not "number" values (such as
strings composed of only digits).

The following code should do what you intended:

<?php

$fibonacci_1000 =
'43466557686937456435688527675040625802564660517371780402481729089536555
417949051890403879840079255169295922593080322634775209689623239873322471
161642996440906533187938298969649928516003704476137795166849228875';

function string_number_format($s)
{
$s = strrev($s); // Needed to avoid '1234' being chunked as '123' &
'4'.
/*
str_split() is a PHP 5 only function...
if you also need to support PHP 4, you can use chunk_split()/wordwrap()
+ explode() to get the same thing.
*/
$s = str_split($s, 3); // $s is now an array dividing the string at
thousands (but using the reversed string)
$s = implode(' ', $s); // Glue thousands together using spaces as
separator.
$s = strrev($); // Put everything back in order.
return $s;
}

echo string_number_format($fibonacci_1000);

?>

Please note that this function is really basic, you may need to adjust
it to your needs.

Hope this helps.

------------------------------------------------------------------------

[2007-08-12 03:52:38] eb1024 at gmail dot com

Description:
------------
Hello, I've used the number_format function to add a thousands
separator to a very large number (the 1000th Fibonacci number), the
thing is that after using the number_format function the number which
originally was

43466557686937456435688527675040625802564660517371780402481729089536555417949051890403879840079255169295922593080322634775209689623239873322471161642996440906533187938298969649928516003704476137795166849228875

becomes,

43466557686937454881639861284285048836044564808501085299792936936934507578446811952241727283693776165701110466238201810459653426841499747856972973922645842460198740218733277412586280377875508003628944833118208

(or better yet):

43 466 557 686 937 454 881 639 861 284 285 048 836 044 564 808 501 085
299 792 936 936 934 507 578 446 811 952 241 727 283 693 776 165 701 110
466 238 201 810 459 653 426 841 499 747 856 972 973 922 645 842 460 198
740 218 733 277 412 586 280 377 875 508 003 628 944 833 118 208

As you can see the difference is huge! I tried it under PHP 5.2.1 and
PHP 4.4 under Windows XP and Fedora Core 6.

More info @
http://www.alixaxel.com/wordpress/2007/05/19/php-math-library/ if you
need it!

Reproduce code:
---------------
$fibonacci_1000 =
'43466557686937456435688527675040625802564660517371780402481729089536555417949051890403879840079255169295922593080322634775209689623239873322471161642996440906533187938298969649928516003704476137795166849228875';

echo number_format($fibonacci_1000, 0, '', ' ');

Expected result:
----------------
43 466 557 686 937 456 435 688 527 675 040 625 802 564 660 517 371 780
402 481 729 089 536 555 417 949 051 890 403 879 840 079 255 169 295 922
593 080 322 634 775 209 689 623 239 873 322 471 161 642 996 440 906 533
187 938 298 969 649 928 516 003 704 476 137 795 166 849 228 875

Actual result:
--------------
43 466 557 686 937 454 881 639 861 284 285 048 836 044 564 808 501 085
299 792 936 936 934 507 578 446 811 952 241 727 283 693 776 165 701 110
466 238 201 810 459 653 426 841 499 747 856 972 973 922 645 842 460 198
740 218 733 277 412 586 280 377 875 508 003 628 944 833 118 208


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=42276&edit=1

Reply via email to