0

I am trying to sum values registred in database as float with EF Core

public async Task<double> ObtenirTotalStockParSiteAsync(long siteId)
            => await Queryable.Where(snapshot => snapshot.SiteId == siteId).SumAsync(snapshot => snapshot.Quantite).ConfigureAwait(false);

The value registred in database is 40,005 enter image description here

But, the value returned with SumAsync is : 40.004999999999995

Can you help please to get 40,005

Quantite has the type float in my Sql Server Database

oumechtak
  • 19
  • 3
  • 1
    https://stackoverflow.com/questions/588004/is-floating-point-math-broken – TheGeneral Oct 03 '21 at 21:28
  • If you need it to be exact you need use `decimal` instead of `float` or `double`. And that would need to be the type in the DB as well. – juharr Oct 04 '21 at 01:18

0 Answers0