Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.6k views
in Technique[技术] by (71.8m points)

MySQL保存 支付金额用 DECIMAL 还是 DOUBLE ?为什么

我之前的习惯一直都是使用DECIMAL(10,2),但是新进入一家公司,他们都是使用DOUBLE(8,2) 疑问的是,MYSQL保存支付金额可以用DOUBLE吗?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

用 decimal ,用 double 在做运算时,可能会出问题.

一般我保存金额,都是以分为单位,直接保存整形进数据.所有的计算都以分为单位,展示层自己转换为以元为单位展示.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...