How to check infinity value? when we passed too large number in String and cast in to float value it will be give infinity. how to catch it?

Questions by Thakkar Nirav   answers by Thakkar Nirav

Showing Answers 1 - 9 of 9 Answers

Aparna

  • Apr 25th, 2006
 

Good Site

  Was this answer useful?  Yes

vikas

  • Apr 26th, 2006
 

Question: How to check infinity value? when we passed too large number in String and cast in to float value it will be give infinity. how to catch it?

  Was this answer useful?  Yes

: How to check infinity value? when we passed too large number in String and cast in to float value it will be give infinity. how to catch it?

  Was this answer useful?  Yes

Java Mortal

  • Apr 26th, 2006
 

Hmm.. I don't have definite answer..

but we can predict by means of size and range.

  Was this answer useful?  Yes

naveen

  • Apr 26th, 2006
 

Hi,

I got answer to you here is the example.

public void setFoo(float foo) {
      if (foo >= 0 && foo < Float.INFINITY)
        this.foo = foo;
      else
        throw new IllegalArgumentException(Float.toString(f));

    }
In Jdk 1.5 its Float.isInfinity(float).

Thanks

Naveen.

  Was this answer useful?  Yes

premisa

  • Apr 28th, 2006
 

s, we can get the output by throws exception method.

that is by extending throws exception from the class method defined.

  Was this answer useful?  Yes

jay

  • Sep 23rd, 2006
 

why not just treat infinty like any other String->float conversion error ? :float myfloat;try { myfloat = Float.parseFloat(floatAsString);} catch (Exception e) { // o-o the format of floatAsString is not quite compatible with java float}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions