MySQL中的Decimal(3,2)值始终为9.99 [英] Decimal(3,2) values in MySQL are always 9.99

查看:429
本文介绍了MySQL中的Decimal(3,2)值始终为9.99的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MySQL中有一个类型为decimal(3,2)的Justsomenum字段,当我插入类似78.3的值时,该字段似乎始终为9.99.为什么?

I have a field, justsomenum, of type decimal(3,2) in MySQL that seems to always have values of 9.99 when I insert something like 78.3. Why?

这是我的桌子的样子:

mysql> describe testtable;
+---------------+--------------+------+-----+---------+----------------+
| Field         | Type         | Null | Key | Default | Extra          |
+---------------+--------------+------+-----+---------+----------------+
| id            | int(11)      | NO   | PRI | NULL    | auto_increment | 
| firstname     | varchar(20)  | YES  |     | NULL    |                | 
| lastname      | varchar(20)  | YES  |     | NULL    |                | 
| justsomenum   | decimal(3,2) | YES  |     | NULL    |                | 
+---------------+--------------+------+-----+---------+----------------+

当我插入这样的内容并选择时:

When I insert something like this and the select:

mysql> insert into testtable (firstname, lastname, justsomenum) values ("Lloyd", "Christmas", 83.5);

选择后我得到9.99.

I get 9.99 when I select.

mysql> select * from testtable;
+----+-----------+-----------+---------------+
| id | firstname | lastname  | justsomenum   |
+----+-----------+-----------+---------------+
|  1 | Shooter   | McGavin   |          9.99 | 
|  2 | Lloyd     | Christmas |          9.99 | 
|  3 | Lloyd     | Christmas |          9.99 | 
|  4 | Lloyd     | Christmas |          9.99 | 
+----+-----------+-----------+---------------+
4 rows in set (0.00 sec)

这是Mac OS X 10.5.8上的MySQL 5.0.86.

This is MySQL 5.0.86 on Mac OS X 10.5.8.

有什么想法吗?谢谢.

推荐答案

decimal(3, 2)的最大值为9.99,因此,当您尝试插入大于该值的内容时,该最大值为9.99.如果要存储更大的数字,请尝试decimal(5, 2)或其他方法.

The maximum value for decimal(3, 2) is 9.99, so when you try to insert something larger than that, it is capped to 9.99. Try decimal(5, 2) or something else if you want to store larger numbers.

第一个参数是精度的位数,第二个参数是小数点后的位数.

The first argument is the total number of digits of precision, and the second argument is the number of digits after the decimal point.

这篇关于MySQL中的Decimal(3,2)值始终为9.99的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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