Decimal result not getting properly.

  • Hi,

    Below query displays result as 0.00 but i want to show as 0.73

    SELECT ROUND(CAST (22/30 AS decimal (6,2)),-2);

    Please suggest where m going wrong.

    Thanks,

    Abhas.

  • SELECT ROUND(CAST (22.0/30 AS decimal (6,2)),2);

    1/ Sql considers 22 and 30 as integers, and so it performs an integer division. So the result is 0. Writing 22.0 force Sql to perform a decimal division.

    2/ -2 as second parameter for ROUND force rounding to 100, not to 0.01 😉

    Roland

  • Thanks Ronald,

    select CAST(22 as decimal (6,2))/CAST(30 as decimal (6,2)) is also giving me output. 🙂

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

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