如何停止对MySQL十进制字段进行四舍五入?

编程入门 行业动态 更新时间:2024-10-17 21:23:55
本文介绍了如何停止对MySQL十进制字段进行四舍五入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在MySQL中有一个表,该表的字段为小数,长度9,无符号.我用它来定价.

I have a table in MySQL with a field that is decimal, length 9, unsigned. I'm using it for prices.

插入数据并查询后,所有数据均已四舍五入,小数点已删除.

After I insert the data, and query for it, it has all been rounded and the decimal has been removed.

我对为什么感到困惑.

故障排除技巧?

主机:web

phpMyAdmin版本:2.11.10.1

phpMyAdmin version: 2.11.10.1

MySQL客户端版本:5.0.95

推荐答案

MySQL中的小数类型有两个调整旋钮:精度和小数位.您省略了小数位,因此默认为0.

Decimal type in MySQL has two tuning knobs: precision and scale. You omitted the scale, so it defaults to 0.

DECIMAL列的声明语法为DECIMAL(M,D). MySQL 5.1中参数的值范围如下:

The declaration syntax for a DECIMAL column is DECIMAL(M,D). The ranges of values for the arguments in MySQL 5.1 are as follows:

M是最大位数(精度).范围是1到65.(较早版本的MySQL允许范围是1到254.)

M is the maximum number of digits (the precision). It has a range of 1 to 65. (Older versions of MySQL permitted a range of 1 to 254.)

D是小数点右边的位数(小数位数).范围是0到30,并且不能大于M.

D is the number of digits to the right of the decimal point (the scale). It has a range of 0 to 30 and must be no larger than M.

示例

mysql> create table test01 (field01 decimal(9)); Query OK, 0 rows affected (0.01 sec) mysql> insert into test01 (field01) values (123.456); Query OK, 1 row affected, 1 warning (0.00 sec) mysql> select * from test01; +---------+ | field01 | +---------+ | 123 | +---------+ 1 row in set (0.00 sec) mysql> create table test02 (field01 decimal(9, 4)); Query OK, 0 rows affected (0.00 sec) mysql> insert into test02 (field01) values (123.456); Query OK, 1 row affected (0.01 sec) mysql> select * from test02; +----------+ | field01 | +----------+ | 123.4560 | +----------+ 1 row in set (0.00 sec)

更多推荐

如何停止对MySQL十进制字段进行四舍五入?

本文发布于:2023-11-10 02:44:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1574124.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   四舍五入   MySQL   十进制

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!