Problemi di Arrotondamento
Salve a tutti,
Sto avendo alcuni problemi, nell'arrotondamento dei decimali.
Il campo importo_p è un DOUBLE e Uso tabelle MyIsam.
Non riesco a spiegarmi questa cosa:
1)Arrotondamento corretto per l'applicazione di cui ho bisogno
mysql> SELECT round(8.025,2);
+----------------+
| round(8.025,2) |
+----------------+
| 8.03 |
+----------------+
1 row in set (0.00 sec)
2)Ora facendo fare i calcoli a mysql , risuta corretto (guardate la seconda riga, è esattamenten 8.02500).
mysql> SELECT importo_p,round(importo_p/1.200,5) as totale FROM articoli WHERE id_fattura='2010/001';
+-----------+---------+
| importo_p | totale |
+-----------+---------+
| 0.9 | 0.75000 |
| 9.63 | 8.02500 |
+-----------+---------+
2 rows in set (0.00 sec)
3)Ora se faccio fare il round a 2 cifre, non arrotonda la seconda riga a 8.03 ma a 8.02
mysql> SELECT importo_p,round(importo_p/1.2,2) as totale FROM articoli WHERE id_fattura='2010/001';
+-----------+--------+
| importo_p | totale |
+-----------+--------+
| 0.9 | 0.75 |
| 9.63 | 8.02 |
+-----------+--------+
Come mai? Mi sono perso qualcosa per strada?
Vi ringrazio in anticipo per le eventuali risposte!
Ciao, Davide
Subject
Views
Written By
Posted
Problemi di Arrotondamento
6693
December 24, 2010 05:07AM
2835
December 27, 2010 06:22PM
1624
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.