Bug #34369 | Casting a float to a decimal returns wrong result | ||
---|---|---|---|
Submitted: | 7 Feb 2008 1:29 | Modified: | 7 Feb 2008 4:28 |
Reporter: | Baron Schwartz (Basic Quality Contributor) | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: Data Types | Severity: | S3 (Non-critical) |
Version: | 5.0.45 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | qc |
[7 Feb 2008 1:29]
Baron Schwartz
[7 Feb 2008 4:28]
Valeriy Kravchuk
Thank you for a problem report. I was able to repeat the behaviour described, but I think this is not a bug. If you cast to DECIMAL(N,N), the largest value you can represent by this type is .999999... where number of 9s is N. The value you cast (2.2) is bigger, so as usual for MySQL it is converted to largest possible and you get a warning. Like in this case: mysql> select cast(1000 as decimal(3)); +--------------------------+ | cast(1000 as decimal(3)) | +--------------------------+ | 999 | +--------------------------+ 1 row in set, 1 warning (0.00 sec)