I need to use the value 0.3. I am using float for this. Now when I move the mouse of this variable in VS2010, it tells me 0.2999999 instead of 0.3.
But I would really need the 0.3.
Can anybody tell me how this can be done? Thank you.
I need to use the value 0.3. I am using float for this. Now when I move the mouse of this variable in VS2010, it tells me 0.2999999 instead of 0.3.
But I would really need the 0.3.
Can anybody tell me how this can be done? Thank you.
This depends on what you're trying to do. If you're trying to do something if the value is 0.3, you could try if (x > 0.29 && x < 0.31)
, although this won't be completely accurate. But other than this the first comment is right, there is no way to get the value accurately.
I would comment before posting to check what is being done, but I lack the reputation to do so. If this turns out to be inaccurate, I will happily delete this answer, so please don't be too quick to downvote.
EDIT: you could also try storing the number as ten times larger and comparing for 3, but I wouldn't recommend this. Please provide details of why this needs to be done.