Discussion: Rounding not working
Afficher un message
Vieux 25/03/2008, 20h29   #2
Plamen Ratchev
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Rounding not working

Running this will explain it:

SELECT 575629 / 54

When integer dividend is divided by an integer divisor the result is an
integer that has any fractional part of the result truncated, so you get
10659.

But try this:
SELECT CAST(575629 / 54.0 AS DECIMAL(10 , 0))

or

SELECT CAST(1.0 * 575629 / 54 AS DECIMAL(10 , 0))

Those will give you the expected result 10660, because the higher precedence
argument data type is the resulting data type of the division.

HTH,

Plamen Ratchev
http://www.SQLStudio.com

  Réponse avec citation
 
Page generated in 0,04244 seconds with 9 queries