November 1, 2011 at 2:44 pm
I am having a random rounding issue and wondering if someone has dealt with this.
I have two fields PayUnit float = 31.93 , PayRate Money =8.50
PayUnit* PayRate= 31.93*8.5= 271.405
With the code below - it is randomly rounding it to 271.41 sometimes and 271.40 other times. What am I doing wrong>
SELECT ROUND(CAST(tei.PayUnit AS MONEY)* tei.PayRate, 2)
Any ideas?
November 1, 2011 at 2:50 pm
well remember floats are stored as approximations, so i'd suspect witht eh full details, that's where the issue lies.
SQL
with the one exampel you offered, i don't see anything specific to offer;
/*
--Results:
PayUnitPayRate(No column name)(No column name)
31.938.50271.405271.41
*/
With tei AS
(
SELECT PayUnit = CONVERT(float,31.93),
PayRate = CONVERT(Money, 8.50)
)
SELECT PayUnit,
PayRate,
PayUnit * PayRate,
ROUND(CAST(tei.PayUnit AS MONEY)* tei.PayRate, 2)
from tei
Lowell
November 1, 2011 at 3:07 pm
Thanks for the response. I was aware of the float issue and the hope was the casting the Payunit to Money would solve that. I have reconfirmed the Payrate is Money.
One thing to add to this is that this gets rounded the right way on multiple servers however I am having this issue on a specific server and on that too it is random.
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply