How can I format my data to 2 decimal numbers in sql ?
select numericColumn from table1
ex :-
numericColumn
10.22
20.00
30.45
12.02
regards
ypul
ypul wrote:
> How can I format my data to 2 decimal numbers in sql ?
> select numericColumn from table1
> ex :-
> numericColumn
> --
> 10.22
> 20.00
> 30.45
> 12.02
> regards
> ypul
What data type are you using in the table?
David Gugick
Quest Software
www.imceda.com
www.quest.com
|||numericcolumn datatype is float
ypul
"David Gugick" <david.gugick-nospam@.quest.com> wrote in message
news:%23cf2O3PnFHA.2472@.TK2MSFTNGP15.phx.gbl...
> ypul wrote:
> What data type are you using in the table?
> --
> David Gugick
> Quest Software
> www.imceda.com
> www.quest.com
|||ypul wrote:
> numericcolumn datatype is float
> ypul
>
Probably using the wrong data type. Why have you chosen to use an
approximate data type like float/real instead of DECIMAL/NUMERIC which
stores an exact represenation of a number? Do you really need to store.
From BOL:
"Approximate number data types for use with floating point numeric data.
Floating point data is approximate; not all values in the data type
range can be precisely represented."
If you either must use a float or cannot change the data type to
something more appropriate, you have two options:
1- Format the numeric data on the client - client formatting is
preferred over using SQL Server to do the same
2- Use the CAST function, but you may have to deal with rounding issues
For example:
Declare @.f real
Set @.f = .05
Select @.f -- Returns 5.5500001E-2
Select CAST(@.f as NUMERIC(10, 2)) -- Returns .06
David Gugick
Quest Software
www.imceda.com
www.quest.com
|||Thanks Buddy
that was very very .....helpful !!
ypul
"David Gugick" <david.gugick-nospam@.quest.com> wrote in message
news:e8NGR%23SnFHA.2860@.TK2MSFTNGP15.phx.gbl...
> ypul wrote:
> Probably using the wrong data type. Why have you chosen to use an
> approximate data type like float/real instead of DECIMAL/NUMERIC which
> stores an exact represenation of a number? Do you really need to store.
> From BOL:
> "Approximate number data types for use with floating point numeric data.
> Floating point data is approximate; not all values in the data type
> range can be precisely represented."
> If you either must use a float or cannot change the data type to
> something more appropriate, you have two options:
> 1- Format the numeric data on the client - client formatting is
> preferred over using SQL Server to do the same
> 2- Use the CAST function, but you may have to deal with rounding issues
> For example:
> Declare @.f real
> Set @.f = .05
> Select @.f -- Returns 5.5500001E-2
> Select CAST(@.f as NUMERIC(10, 2)) -- Returns .06
>
> --
> David Gugick
> Quest Software
> www.imceda.com
> www.quest.com
>
No comments:
Post a Comment