C# : Number Conversion Problem

Posted by Sayem Ahmed on Stack Overflow See other posts from Stack Overflow or by Sayem Ahmed
Published on 2010-03-27T09:46:29Z Indexed on 2010/03/27 9:53 UTC
Read the original article Hit count: 247

Filed under:
|

Today I faced a strange problem in C#. I have an ASP.NET page where user can enter certain price, quantity etc. I get the price value, convert it to double, then multiply it with 100 and then typecast it to an integer. When the price is "33.30", after converting it to double it remains 33.3 (obviously...), but after multiplying it with 100, it becomes 3329.9999999999995, and when I cast it to integer by applying simple cast operator "(int) (price * 100) ", it becomes 3329.

Right now I have no idea why this is happening. So I thought may be you guys can help :) .

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about c#