MySQL Forums
Forum List  »  Italian

Re: Problemi di Arrotondamento
Posted by: Gavin Towey
Date: December 27, 2010 06:22PM

E' importante usare DECIMAL invece di float/double quando si vuole numeri esatti -- specialmente con il denaro:

mysql> create table testd ( a double, b decimal(7,2) );

mysql> insert into testd ( 9.63, 9.63 );
mysql> insert into testd values ( 9.63, 9.63 );
mysql> insert into testd values (0.9 , 0.9 );

mysql> select a, round(a/1.2,2) as total_1, round(b/1.2,2) as total_2 FROM testd;
+------+---------+---------+
| a | total_1 | total_2 |
+------+---------+---------+
| 9.63 | 8.02 | 8.03 |
| 0.9 | 0.75 | 0.75 |
+------+---------+---------+
2 rows in set (0.00 sec)


Come si vede, quando il campo e' DECIMAL, il risulto e' coretto.

Options: ReplyQuote


Subject
Views
Written By
Posted
6346
December 24, 2010 05:07AM
Re: Problemi di Arrotondamento
2766
December 27, 2010 06:22PM
1573
December 28, 2010 02:52AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.