storing money amounts in mysql

后端 未结 7 655
野趣味
野趣味 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条回答
  •  -上瘾入骨i
    2020-11-29 20:26

    If you use DECIMAL or NUMERIC types, you can declare them as for example DECIMAL(18, 2) which would force 2 decimals even if they were 0. Depending on how big values you expect you can change the value of the first parameter.

提交回复
热议问题