PHP Integer Problem

后端 未结 5 2071
一生所求
一生所求 2021-01-14 19:42

When I print this number in php 137582392964679 I get this as the output 1.37582392965E+14

All I am doing is a simple



        
5条回答
  •  情深已故
    2021-01-14 20:10

    That number is too big to fit into a 32-bit integer, so yes, it is converting to a floating point type automatically. How to get around it depends on the requirements of your system. If you aren't going to do any arithmetic then just store it as a string. If precision isn't overly important then you could leave it as a float and format it using printf. If precision is important and you can upgrade to 64-bit that should fix it, if you can't upgrade and you need an integer then you could look into using the BC Math PHP extension.

提交回复
热议问题