September 11, 2008 at 12:17 pm
I'm working with a table that has a column "QUANTITY" defined as type = float.
Data can come in from the application with a variety of decimal precision - whatever the user enters, e.g.:
565
123.45678
17.7
In a query of this table, I'd like to show a uniform number of decimal places. I tried round(QUANTITY, 2) but that results in
565
123.46
17.7
What I'd want is
565.00
123.46
17.70
Is there a format mask that can be applied to the variable?
Thank you,
Ellen
September 11, 2008 at 2:09 pm
Use SELECT CAST(@myval AS DECIMAL(10,2))
For example:
DECLARE @myval AS FLOAT
SET @myval = 123.45678
SELECT CAST(@myval AS DECIMAL(10,2))
result: 123.46 (note the rounding)
Next example:
DECLARE @myval AS FLOAT
SET @myval = 565
SELECT CAST(@myval AS DECIMAL(10,2))
result 565.00
Will this satisfy your needs?
September 11, 2008 at 2:22 pm
Perfect, Thanks!
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply