storing money amounts in mysql

后端 未结 7 674
野趣味
野趣味 2020-11-29 19:36

I want to store 3.50 into a mysql table. I have a float that I store it in, but it stores as 3.5, not 3.50. How can I get it to have the trailing zero?

7条回答
  •  伪装坚强ぢ
    2020-11-29 20:26

    Binary can't accurately represent floating points with only a limited number of bits. It's not so muuch loss of data but actually conversion errors.. Here's the manual giving examples

    You can see this in action in your browser, see for yourself in this code snippet.

提交回复
热议问题