3

Please have a look at the following code

private List createTheDynamicWordList(String algorithm, double averageStat)
    {

        Toast.makeText(context, ""+averageStat, Toast.LENGTH_LONG).show();
}

in some cases, I get the averageStat as a 'NaN' value. I need to check whether the number if 'NaN' or not. How can I do this? Using NumberFormatException here didn't work.

halfer
  • 19,824
  • 17
  • 99
  • 186
PeakGen
  • 21,894
  • 86
  • 261
  • 463
  • How can you possibly get `averageStat` as `NaN`? Are you sure you're working in Java and not JavaScript? – Aleks G Aug 20 '13 at 09:02
  • @AleksG: Yes. This is a kind of statistic generation from a database. When "Divide By 0" I have to get this. I couldn't track it with exception handling, maybe because it is inside a loop – PeakGen Aug 20 '13 at 09:08

2 Answers2

25

in your case should be enough:

   if (Double.isNaN(averageState))

take a look here

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
5

Use static method Double.isNaN()

Leszek
  • 6,568
  • 3
  • 42
  • 53