November 4, 2002 at 4:43 am
Could anyone please advise me on the correct operator to use to return the result (to 2 decimal places) of a mathematical division. eg: I have tried 20/3 but only end up with 6. Do I need to use an expression which involves Modulus and build a string, or is it much simpler.
November 4, 2002 at 5:04 am
Best way is to add a decimal position to either the 20 or the 3 then cast into it's final format. Like this
CAST(20.0/3 as decimal(10,2))
The problem you are running into is that 20 and 3 wil be cast automaically to int type and thus the result is an int value. By adding a decimal position to either this will cause the fianl product to be numeric. Works great ike this with only 2 positions. If it had needed to be more you may have to cast at least on into a numeric value with a scale for the proper number of positions to return.
November 4, 2002 at 5:39 am
Thanx Antares686. This works a treat.
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply