MySQL 转换为十进制不能按预期工作 [英] MySQL cast as decimal not working as expected

查看:59
本文介绍了MySQL 转换为十进制不能按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个查询:

SELECT CAST(30.123456789012345 AS DECIMAL(16,16))

返回 0.9999999999999999.

除非我完全弄错了,否则它应该返回30.1234567890123450.

Unless I got it completely wrong, it should return 30.1234567890123450.

谁能解释一下这是怎么回事?

Can anyone please explain what's going on?

谢谢!

推荐答案

您需要 DECIMAL(18,16).

16,16 保留小数点右侧值的所有 16 位可用精度数字.

16,16 reserves all 16 available digits of precision for values to the right of the decimal point.

这篇关于MySQL 转换为十进制不能按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆