Int question


Web tier: servlets, JSP, Web frameworks: Int question

  1. Int question (3 messages)

    How can I check if a value is a number or not. Should I use NAN?


    Threaded Messages (3)

  2. Int question[ Go to top ]

    U can use static method Character.isDigit(char).
  3. Int question[ Go to top ]

    just pass the value as parameter to the NaN function and check the returned value.
  4. Int question[ Go to top ]

    Did you mean to test whether or not a String is a number? Or whether an integer value is????

    NaN is actually a Java constant and isNaN(...) is a method in Double and Float to test whether a given double or float is NaN, so I'm not sure that will help you.

    If you test using Character.isDigit(...) you'll have to loop through the individuals characters of a String. But then beware that values like "1,000.13" would fail because of the comma and decimal point.

    Experiment with the parse(...) method in the java.text.NumberFormat class.