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
2009-01-14 01:40:00
It can also be declared as DECIMAL(10, 2).
jrcs3
2009-01-14 01:54:06
@jrcs3 - Good catch.
Jamie Lewis
2009-01-14 02:00:37
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
2009-01-14 02:16:05
@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
2009-01-14 02:23:36
+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
2009-01-14 01:42:10