Bug #63126 | cannot perform a precise calculation with decimal data | ||
---|---|---|---|
Submitted: | 7 Nov 2011 2:16 | Modified: | 7 Dec 2011 4:55 |
Reporter: | jess Balint | Email Updates: | |
Status: | No Feedback | Impact on me: | |
Category: | MySQL Server: Data Types | Severity: | S3 (Non-critical) |
Version: | 5.5.16 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | decimal, precision |
[7 Nov 2011 2:16]
jess Balint
[7 Nov 2011 4:55]
Valeriy Kravchuk
That's probably related to the fact that MySQL consider numeric constants as DOUBLE (not DECIMAL(M,N)). Look: macbook-pro:5.5 openxs$ bin/mysql -uroot test Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.5.17-debug Source distribution Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> select 1/1.03; +--------+ | 1/1.03 | +--------+ | 0.9709 | +--------+ 1 row in set (0.00 sec) mysql> select cast(1/1.03 as decimal(30,20)); +--------------------------------+ | cast(1/1.03 as decimal(30,20)) | +--------------------------------+ | 0.97087378600000000000 | +--------------------------------+ 1 row in set (0.00 sec) mysql> select cast(1/1.03 as decimal(40,30)); +----------------------------------+ | cast(1/1.03 as decimal(40,30)) | +----------------------------------+ | 0.970873786000000000000000000000 | +----------------------------------+ 1 row in set (0.00 sec) mysql> select cast(1 as decimal(40,30))/cast(1.03 as decimal(40,30)); +--------------------------------------------------------+ | cast(1 as decimal(40,30))/cast(1.03 as decimal(40,30)) | +--------------------------------------------------------+ | 0.970873786407766990291262135922 | +--------------------------------------------------------+ 1 row in set (0.00 sec) So, this is probably not a bug, but just a (sad) result of this documented "feature".
[7 Dec 2011 7:00]
Bugs System
No feedback was provided for this bug for over a month, so it is being suspended automatically. If you are able to provide the information that was originally requested, please do so and change the status of the bug back to "Open".