I do not know why Ceiling behave like in the below image
Why is processingFee != Settings.PaymentProcessingFeeInPercentage * prizesSum ?
alt text http://img514.imageshack.us/img514/3950/csharpceilingproblem.png
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your percentage isn’t actually 0.05. It’s a value close to 0.05… and probably a little bit more than 0.05. Thus when it’s multiplied by 2600, you’re getting a value just over 130.0… which is then being “ceilinged” to 131.0.
Using a little tool I wrote a while ago (available from this page about .NET binary floating point types) it looks like the actual
floatvalue closest to 0.05 is 0.0500000007450580596923828125. For doubles, it’s 0.05000000000000000277555756156289135105907917022705078125.Moral of the story: don’t use
floatfor this sort of thing – usedecimal. Or if you’re just trying to represent a percentage, if it’s okay to actually be only accurate to one percent, use an integer value 0-100.