rounding issues

  • Hello,

    I have a report that I am reverse engineering. The percentage for a specific column is 52.80%, but in my result set I continue to get 53. It's obviously rounding the number. Does anyone have a quick script that can convert this whole number to 52.80?

    Any help would be appreciated.

    Dave

  • DECLARE @Number NUMERIC(5, 2) = 52.8

    Seriously though, we would need to see your code. It sounds like a conversion issue but hard to tell.

    The SQL Guy @ blogspot[/url]

    @SeanPearceSQL

    About Me[/url]

  • Apologies. Here it is....

    round(cast(sum(columnname) as float)*100,3)PrcntSvcLvl

  • What value does this give you?

    SELECT CAST(SUM(columnname) AS FLOAT)

    The SQL Guy @ blogspot[/url]

    @SeanPearceSQL

    About Me[/url]

  • 0.53

  • That is 53%

    How about:

    SELECT SUM(CAST(columnname AS FLOAT))

    The SQL Guy @ blogspot[/url]

    @SeanPearceSQL

    About Me[/url]

  • What is the data type of 'columnname'?

    casting the sum as a float is no good if it was not one before. The precision has been lost before the conversion

  • 0.53

  • numeric(5,2)

  • I can only conclude that the correct value is 53% and not 52.8%.

    The SQL Guy @ blogspot[/url]

    @SeanPearceSQL

    About Me[/url]

  • I can easily change the datatype column. What should that be? Decimal?

  • Thanks very much for your time Sean.

  • Where did you get the conclusion that the answer should be 52.8? Can you give us sample data?

  • What does:

    round(cast(sum(columnname) as numeric(5,3))*100.00,3)

    give you?


    And then again, I might be wrong ...
    David Webb

Viewing 14 posts - 1 through 13 (of 13 total)

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