Wrong result when using bigint in sql query

I went below AmountDue in the request, but getting the wrong result. The AmountDue data type is Float.

AmountDue: 2412880.28 AmountDue: 561.06 

My request:

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

I get below results that are incorrect:

 241288027 56105 

The correct result is:

 241288028 56106 
+4
source share
2 answers

try converting to a numeric value 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 explains the reason for this here.

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

SQL FIDDLE

+1
source

Source: https://habr.com/ru/post/1479817/


All Articles