How can I format numeric results?

  • 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

  • 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?

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

  • Perfect, Thanks!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply