C# quick example of handling Infinity and NaN



If you've enjoyed reading this post then please subscribe to my Full Text RSS Feed.
prog

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

Related Posts

About the Author

a tech junkie and a software developer. a apple fan and an avid photographer. a frequent traveller and loves art and graphic novels. My Google+