How do I print a double value without scientific notation using Java?

前端 未结 14 870
一整个雨季
一整个雨季 2020-11-21 11:52

I want to print a double value in Java without exponential form.

double dexp = 12345678;
System.out.println(\"dexp: \"+dexp);

It shows this

14条回答
  •  遥遥无期
    2020-11-21 12:22

    This may be a tangent.... but if you need to put a numerical value as an integer (that is too big to be an integer) into a serializer (JSON, etc.) then you probably want "BigInterger"

    Example:

    value is a string - 7515904334

    We need to represent it as a numerical in a Json message:

    {
        "contact_phone":"800220-3333",
        "servicer_id":7515904334,
        "servicer_name":"SOME CORPORATION"
    }
    

    We can't print it or we'll get this:

    {
        "contact_phone":"800220-3333",
        "servicer_id":"7515904334",
        "servicer_name":"SOME CORPORATION"
    }
    

    Adding the value to the node like this produces the desired outcome:

    BigInteger.valueOf(Long.parseLong(value, 10))
    

    I'm not sure this is really on-topic, but since this question was my top hit when I searched for my solution, I thought I would share here for the benefit of others, lie me, who search poorly. :D

提交回复
热议问题