PDA

View Full Version : How to limit the precision of computation results


MattNolan
10-10-2009, 01:34 PM
Just simple
Select decimal/decimal as res from table

how do I get res to be 10,2 instead of the default which has alot of precision

Old Pedant
10-10-2009, 08:49 PM
What kind of database???

Yes, it matters. A lot.

Old Pedant
10-10-2009, 09:26 PM
Ehhh...silly me! I forgot what forum I was reading! I would *assume* you mean MySQL since you are posting in a MySQL forum.

http://dev.mysql.com/doc/refman/5.1/en/cast-functions.html


SELECT CAST( ( radius * SIN(angle * 3.14159265 / 180) ) AS Decimal( 10, 2 ) ) AS height
FROM whatever ...

MattNolan
10-10-2009, 11:23 PM
Ehhh...silly me! I forgot what forum I was reading! I would *assume* you mean MySQL since you are posting in a MySQL forum.

http://dev.mysql.com/doc/refman/5.1/en/cast-functions.html


SELECT CAST( ( radius * SIN(angle * 3.14159265 / 180) ) AS Decimal( 10, 2 ) ) AS height
FROM whatever ...


That worked, thanks a bunch