2

Possible Duplicate:
Show more digits in PHP

Let me give some background information about my problem. We have an old legacy application which is being migrated to a different server. In the new server we find that long floating point numbers are getting printed in scientific notations - this was not the case in our previous server.

E.g.:

$num1 = 60000000000.0;
$num2 = 2000000000.0;
$sum  = $num1 + $num2;
echo $sum; //prints 6.2E+10 in new server but 62000000000 in old one..

Now, I do know that we can use number_format() or printf() etc to fix this. However my problem is that such calculations are far too many in the application and it will be very difficult to change all instances.

So can anyone help me with my situation? Is there a global solution? Something configurable maybe in php.ini or something? Can anyone give me any pointers why this works fine in old server but not in new? What server settings might be causing this?

Any help is very much appreciated!

Community
  • 1
  • 1
Undefined Variable
  • 4,196
  • 10
  • 40
  • 69

1 Answers1

5

It depends on the precision ini setting:

http://php.net/manual/en/ini.core.php#ini.precision

Will differ result, is capped on top. Your data as an example on some random system and the precision setting (it defaulted to 14 on that system):

 0: 6.0E+10     7: 6.2E+10        14: 62000000000
 1: 6.0E+10     8: 6.2E+10        15: 6.2E+10    
 2: 6.2E+10     9: 6.2E+10        16: 6.2E+10    
 3: 6.2E+10    10: 6.2E+10        17: 6.2E+10    
 4: 6.2E+10    11: 62000000000    18: 6.2E+10    
 5: 6.2E+10    12: 62000000000    19: 6.2E+10    
 6: 6.2E+10    13: 62000000000    20: 6.2E+10    
hakre
  • 193,403
  • 52
  • 435
  • 836
deceze
  • 510,633
  • 85
  • 743
  • 889