C# quick example of handling Infinity and NaN
Posted on April 26, 2009
Filed Under Programming | Leave a Comment
| If you've enjoyed reading this post then please subscribe to my Full Text RSS Feed. |

In C# programming you may come across instances where you have to compute numbers especially division of numbers which will return a NaN (Not a Number) or Infinity, when dividing by zero.
You can use two methods to check if a number is NaN of Infinity. The two methods are IsNaN and IsInfinity.
Here are the examples:
IsNaN
if (double.IsNaN(per))
{
per = 0.0;
}
IsInfinity
if (double.IsInfinity(per)) {
per = 100;
}
Sphere: Related Content
Other Related Posts:
If you've enjoyed reading this post then why not subscribe to received updates by email.
Email This Post
Trackback This Post
Comments
Leave a Reply








