note 35539 deleted from function.printf by tomsommer

From: Date: Sat, 10 Jul 2004 00:03:48 +0000
Subject: note 35539 deleted from function.printf by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-72951@lists.php.net to get a copy of this message
Note Submitter: keith@ksmith.com ---- I'm not sure if it is a feature or a bug :) but it's definately a gotcha! The length.precison in a printf float is different from any other language's printf. The difference is outlined below in a small program written in C, PERL, and PHP using the printf function: In C: ...>cat pf-test.c main() { printf("12345678901234567890\n"); printf("%09.2f\n",22.0/7.0); } ...>gcc pf-test.c -o pf-test ...>./pf-test 12345678901234567890 000003.14 NOTE: Nine *total* displayed chars, two behind the decimal Now PERL: ...>cat pf-test.pl #!/usr/bin/perl printf("12345678901234567890\n"); printf("%09.2f\n",22.0/7.0); ...>perl pf-test.pl 12345678901234567890 000003.14 NOTE: *Identical* to 'C' (and awk, and ...) Now PHP: ...>cat pf-test.php <?php printf("123456789012340567890\n"); printf("%09.2f\n",22.0/7.0); ?> ...>php -q pf-test.php 123456789012340567890 000000003.14 NOTE: Nine digits before the decimal, the decimal, and two places after. This tends to hide in proportional fonts, but can cause wierd alignment issues and gaps, particularly if you are using pre-formatted mono-spaced text.

« previous php.notes (#72951) next »