Saturday, February 25, 2012

ROUND unexpected result

/*********** Script 1 **************/
declare @.nr_1 as decimal (10,2)
declare @.nr_2 as decimal (10,2)
set @.nr_1=5
set @.nr_2=3
select round(@.nr_1/@.nr_2,0)

RESULT = 2

/*********** Script 2 **************/

select round(5/3,0)

RESULT = 1

What it is the explication for these difference ?select round(5/3,0), 5/3, 5.0/3.0

Floating point vs integer math.

No comments:

Post a Comment