Reputation: 759
it s enough to round a column value in plsql by using round(value,2)
. For example 1.2222 can be converted to 1.22 by that function in plsql.
How can I do that in SQL Server? When I use round(1.2222,2)
, it converts 1.2200. I want 1.22. Thanks for help
Upvotes: 3
Views: 1860
Reputation: 2017
decimal(10,4) and decimal(10,2) are two different types. so 25.55 and 25.5555 are different types. but if you use float(4), then those two numbers are same data types.
Upvotes: 0
Reputation: 30892
Mathematically, 1.2200 and 1.22 are the exact same number.
The display of the number is actually a string that is different from the physical content of the number, so the number is rounded the same in SQL Server and Oracle, it's just displayed diferently.
More, about SQL float point types: if you declare a variable as having a s decimal places, it will always display as having s decimal places, regardless of the value, for example
declare @x decimal(10,6)
declare @y decimal(10,2)
set @x =3
set @y=@x -- identical to set @y=cast(@x as decimal(10,2))
select @x -- selects 3.000000
select @y -- selects 3.00
select 'The number is ' + cast(@x as varchar) -- selects 'The number is 3.000000'
select 'The number is ' + cast(@y as varchar) -- selects 'The number is 3.00'
However, there is a technical difference about the meaning of 3.00 and 3.0000, and that's the relative error of the number. Since all real numbers are rounded, 3.00 actually means 3 +/- 0.005 , and 3.0000 is actualy 3 +/- 0.00005, as more significant digits are known.
Upvotes: 5