Wednesday 27 May 2015

Convert a number to two decimal places in SQL Server Query

Many a times we get some number(float or double) from our sql query operation. But at the end we need a two decimal number. Then how can we achieve this

2 comments:

  1. Solution 1:
    SELECT CONVERT(DECIMAL(10,2),Number)
    Replace the number with the expression you want to change to two decimal

    ReplyDelete
  2. Solution 2:
    FORMAT(NumberorExpression,'##.##')
    Disadvantage here using this method 44.440 will be converted to 44.44 but 44.000 will be converted to 44 only.
    So when there is only zero after decimal then it simply returns the integer value.

    ReplyDelete