开发者

Mysql: money and floats

开发者 https://www.devze.com 2022-12-22 02:58 出处:网络
What float do I need to store such sums like these: $1,200,000, $1,000, and $14.56 ? ($ dosn\'t count; it will be remo开发者_如何学运维ved)Don\'t. Store as an int and multiply/divide by 100. e.g. Stor

What float do I need to store such sums like these: $1,200,000, $1,000, and $14.56 ? ($ dosn't count; it will be remo开发者_如何学运维ved)


Don't. Store as an int and multiply/divide by 100. e.g. Store 14.56 as 1456, but /100 when displaying. Floating point for storing currency is just asking for rounding problems.


Try DECIMAL. See http://dev.mysql.com/doc/refman/5.1/en/numeric-types.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号