Using Float is not working in SQL Server 2008 -


i have sql query

select      exchangerate,     totalamt,     exchangerate * totalamt totalamtconvert,     round(exchangerate * totalaramt, 0) totalamtround       dbo.table 

my results:

  • exchangerate 22450
  • totalamt 16593.67
  • totalamtnoround 372527891.5
  • totalamtround 372527891

i want totalamtround = 372527892

can me?

this reason use should not use float. approximate datatype. use decimal or numeric datatypr

declare @exchangerate  numeric(22, 6) = 22450,          @totalamt      numeric(22, 6) = 16593.67,          @exchangerate1 float = 22450,          @totalamt1     float = 16593.67   select numeric_result = round(@exchangerate * @totalamt, 0), --correct        float_result = round(@exchangerate1 * @totalamt1, 0), --incorrect        converted_numeric_result= round(cast(@exchangerate1 numeric(22, 6))                                           * cast(@totalamt1 numeric(22, 6)), 0) --correct 

when select @exchangerate1 * @totalamt1 gives 372527891.49999994 @exchangerate * @totalamt gives 372527891.5.

result :

╔════════════════╦═══════════════╦══════════════════════════╗ ║ numeric_result ║ float_result  ║ converted_numeric_result ║ ╠════════════════╬═══════════════╬══════════════════════════╣ ║      372527892 ║     372527891 ║                372527892 ║ ╚════════════════╩═══════════════╩══════════════════════════╝ 

Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -