|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-10-20 15:41 UTC] owner at dragon-hearts dot net
Description: ------------ When using mathematical processes on numbers over 1 million the result comes out in scientific notation instead of as a normal integer. Tested on PHP 5.2.1 it works as expected on 5.2.2 and above it doesn't. I checked the change log and nothing is mentioned about this. Reproduce code: --------------- $var1=1; $var2=7000000; echo $var1*$var2; Expected result: ---------------- 7000000 Actual result: -------------- 7E+6 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 20:00:01 2025 UTC |
I am receiving longs via SOAP responses which represent IDs of accounts. Due to some issue with PHP and long values when we retrieve accounts using the same IDs we receive, we get other peoples' accounts back - not good! I have found the core problem and the snippet of code below shows that the correct ID of 285000000003622757 is transformed into the incorrect ID of 285000000003622752 (last number goes down 5). <?php $long = 285000000003622757; function f0($long) { return $long; } function f1($long) { return sprintf ( "%.0f", $long ); } function f2($long) { return number_format($long, 0, '.', ''); } ?> <h1>F0 (no formatting) </h1> <?= f0($long) ?> <h1>F1 (sprintf) </h1> <?= f1($long) ?> <h1>F2 (number_format) </h1> <?= f2($long) ?> OUTPUT ====== F0 (no formatting) 2.85000000004E+17 F1 (sprintf) 285000000003622752 F2 (number_format) 285000000003622752