Question

I have values stored as 0.05 and 0.10 in the database. I am creating a list using c# code to get these values in the list using :

foreach (var objST in obj.LstTerms)
{
     SubcriptionTermsModel objSubcriptionTerms = new SubcriptionTermsModel();
     objSubcriptionTerms.DiscountRate = objST.DiscountRate;
}

where DiscountRate is of type double. But when creating a list the value 0.10 is truncated as 0.1 which I am unable to compare on my view. Kindly help me with the solution for this.

Was it helpful?

Solution

As discussed here

double doesn't keep insignificant digits - there's no difference between 1.5 and 1.50000 as far as double is concerned.

If you want to preserve insignificant digits, use decimal instead. It may well be more appropriate for you anyway, depending on your exact context. (We have very little context to go on here...)

So you can use this decimal instead of double

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top