PHP money string conversion to integer error

后端 未结 9 689
小蘑菇
小蘑菇 2021-01-13 21:43

I have a small financial application with PHP as the front end and MySQL as the back end. I have ancient prejudices, and I store money values in MySQL as an integer of cents

9条回答
  •  既然无缘
    2021-01-13 22:13

    You should never ever store currency in floating point, because it always get results you don't expect.

    Check out php BC Maths, it allow you to store your currency as string, then perform very high precision arithmetic on them.

提交回复
热议问题