문제

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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top