user2205924
user2205924

Reputation: 471

Getting wrong result when using bigint in sql query

I have passed below AmountDue in query but am getting wrong result. AmountDue data type is Float.

AmountDue: 2412880.28
AmountDue: 561.06

My query:

select CONVERT(varchar,(select convert(bigint,AmountDue*100)))
from dbo.tblBidResults

I am getting below results which is wrong:

241288027
56105

Correct Result:

241288028
56106

Upvotes: 4

Views: 496

Answers (2)

Prahalad Gaggar
Prahalad Gaggar

Reputation: 11609

DECLARE @temp float
set @temp = 2412880.28
select convert(varchar,convert(decimal(9,0),@temp*100))

SQL FIDDLE

Upvotes: 1

Abe Miessler
Abe Miessler

Reputation: 85126

try converting to numeric instead of bigint:

DECLARE @temp float
set @temp = 2412880.28
SELECT CONVERT(varchar,(CONVERT(numeric(27,0),@temp*100)))

There is a good post that goes over the reason for this here.

Upvotes: 1

Related Questions