2012-09-19

Always converting PHP’s floating numbers to string with sprintf

Views: 6539 | Add Comments

I think PHP’s way to deal with float is too BAD!

PHP code:

$a = 12345678.123456;
echo (string) $a; echo "\n";
echo $a.''; echo "\n";
echo sprintf('%f', $a); echo "\n";

Outputs:

12345678.1235
12345678.1235
12345678.123456
Posted by ideawu at 2012-09-19 11:42:37

Leave a Comment