Trying to divide an integer or Decimal number by zero throws a DivideByZeroException exception. To prevent the exception, ensure that the denominator in a division operation with integer or Decimal values is non-zero.
Dividing a floating-point value by zero doesn't throw an exception; it results in positive infinity, negative infinity, or not a number (NaN), according to the rules of IEEE 754 arithmetic
Uh, no. The thing to do would be to test the value you're dividing by first and don't do it if it's zero. Prevention is almost always better than cure.I think I know the answer, cast it as decimal instead of float
Why? Are you porting code from another language which does throw division by zero exceptions and you want to try to keep the ported close as close to the original code as possible?ok, but how do I still a maintain floating point division that also kicks back an exception when someone tries to do division by zero?
Thanks jmcilhinneyUh, no. The thing to do would be to test the value you're dividing by first and don't do it if it's zero. Prevention is almost always better than cure.
No, this is me just trying to practice C# and figuring out ways to do stuff.Why? Are you porting code from another language which does throw division by zero exceptions and you want to try to keep the ported close as close to the original code as possible?