How to properly divide two DECIMAL
values in MySQL and get a result accurate to the number of digits defined in the column type?
Example:
select cast(1/2 as decimal(4,4)),
cast(1 as decimal(4,4))/2,
cast(1 as decimal(4,4))/cast(2 as decimal(4,4));
Results:
'0.5000', '0.49995000', '1.00000000'
Why is the second result innacurate? Why is the third result not '0.5000'?
Note: I can't just use the first form, I need to perform calculations with columns stored as decimals.