Dick Swager
2008-05-22 23:51:52 UTC
I am using the round function in a view in order to display data to a
specified number of decimal places. In general it displays the data as
expected but occasionally there are values that are displayed to many
decimal places. Maybe I should be using some other mechanism to control the
display. Here is code that is similar
declare @x float
declare @y float
set @x = 4.0 * atan (1.0)
set @y = 3.8694336414337158
select
round (@x, 4) as 'pi',
round (@y, 4) as 'offending value'
/* expected result
pi offending value
3.1416 3.8694
*/
/* actual result
pi offending value
3.1416 3.8693999999999997
*/
How should I be doing this to get the desired result?
Now that I think about it, maybe this is a bad practice anyway because if
someone tries to use the value from the view, it will be only an
approximation of the actual value. Is this true?
Thanks, Dick
specified number of decimal places. In general it displays the data as
expected but occasionally there are values that are displayed to many
decimal places. Maybe I should be using some other mechanism to control the
display. Here is code that is similar
declare @x float
declare @y float
set @x = 4.0 * atan (1.0)
set @y = 3.8694336414337158
select
round (@x, 4) as 'pi',
round (@y, 4) as 'offending value'
/* expected result
pi offending value
3.1416 3.8694
*/
/* actual result
pi offending value
3.1416 3.8693999999999997
*/
How should I be doing this to get the desired result?
Now that I think about it, maybe this is a bad practice anyway because if
someone tries to use the value from the view, it will be only an
approximation of the actual value. Is this true?
Thanks, Dick