Ngupta
Ngupta

Reputation: 349

very high float value changing to infinity while retrieving from database

I have an entry in my database

select item_numeric_value from Item_Allowed_Values where id=761 

datatype of item_numeric_value is float in my db.

the result I get is 1.11111111111111E+49.

when I retrieve this value in java in a string , I get infinity.

is there anything I am missing or doing wrong ?

Upvotes: 0

Views: 208

Answers (1)

user4910279
user4910279

Reputation:

You should use double instead of float:

    // Float.MAX_VALUE = 3.4028234663852886E38f
    float f = Float.parseFloat("1.11111111111111E+49");
    System.out.println("f=" + f);   // -> f=Infinity

    // Double.MAX_VALUE = 1.7976931348623157E308
    double d = Double.parseDouble("1.11111111111111E+49");
    System.out.println("d=" + d);   // -> d=1.11111111111111E49

Upvotes: 1

Related Questions