Convert double to float in Java

前端 未结 10 824
执念已碎
执念已碎 2020-12-08 18:13

I am facing an issue related to converting double to float. Actually, I store a float type, 23423424666767, in a database, but when we

10条回答
  •  伪装坚强ぢ
    2020-12-08 18:36

    I suggest you to retrieve the value stored into the Database as BigDecimal type:

    BigDecimal number = new BigDecimal("2.3423424666767E13");
    
    int myInt = number.intValue();
    double myDouble = number.doubleValue();
    
    // your purpose
    float myFloat = number.floatValue();
    

    BigDecimal provide you a lot of functionalities.

提交回复
热议问题