Decimals are not getting stored properly in database using C# .Net

I see issue while storing decimal value in mongodb. I am using C# .Net drivers in my application to insert update in mongodb.

I have below property in class with type double.

 [BsonRepresentation(BsonType.Decimal128)]
 public double? ProductPrice{ get; set; }

In Code we are assigning value for ProductPrice as 38.59 but in collection it got stored like below which is unexpected. I want to get stored whatever value we are assigning to property. It should get stored without extra decimal points.

“ProductPrice” : NumberDecimal(“38.590000000000003”)

why do you use “double” instead of “decimal”?

it does not matter how you store data, it is about how you interpret that data. after all, a decimal number is just another floating point number, but with extra care taken by the language it is interpreted in, which is C# in your case with “decimal” data type. just be careful not to connect with a language having loose or no decimal support.

The Decimal type does not eliminate the need for rounding. Rather, it minimizes errors due to rounding.