views:

15467

answers:

3

How do you write number in two decimal place for sql server?

+1  A: 

Generally you can define the precision of a number in SQL by defining it with parameters. For most cases this will be NUMBER(10,2) - will define a column as a Number with 10 digits with a precision of 2 (decimal places).

Edited for clarity

Jamie Lewis
It can also be declared as DECIMAL(10, 2).
jrcs3
@jrcs3 - Good catch.
Jamie Lewis
This is wrong for several reasons. It's not number, it's numeric or decimal. You say numeric(10,2) allows 10 places before the decimal point, which is also wrong. numeric(10,2) allows for 10 total digits with 2 places after the decimal point. Range = -99999999.99 to 99999999.99
G Mastros
@G Mastros: It appears you are right on the precision point. On the actual naming of the the convention, in many of SQL implementations NUMBER is a valid type. Although I will admit to not knowing the case of sqlserver
Jamie Lewis
+5  A: 

Use Str() Function. It takes three arguments(the number, the number total characters to display, and the number of decimal places to display

  Select Str(12345.6789, 12, 3)

displays: ' 12345.679' ( 3 spaces, 5 digits 12345, a decimal point, and three decimal digits (679). - it rounds if it has to truncate

for a Total of 12 characters, with 3 to the right of decimal point.

Charles Bretana
A: 

try this

SELECT CONVERT(DECIMAL(10,2),10000)