Why does a division result differ based on the cast type?
问题 Here's a part of code that I dont understand: byte b1 = (byte)(64 / 0.8f); // b1 is 79 int b2 = (int)(64 / 0.8f); // b2 is 79 float fl = (64 / 0.8f); // fl is 80 Why are the first two calculations off by one? How should I perform this operation, so its fast and correct? EDIT: I would need the result in byte 回答1: EDIT: Not entirely correct, see: Why does a division result differ based on the cast type? (Followup) Rounding issue: By converting to byte / int, you are clipping of the decimal