1

i would like to convert a string to double and keep it as it is ,for example i have :

719379705 instead of this 7.19379705E8

  • is double type having the capacity to display 719379705 as it is and not in exponential form.

i use this method for conversion :

private double toDouble(String valeur) {
    if (valeur != null) {
        return Double.parseDouble(valeur);
    }
    return Double.NaN;
}

thanks

Arezki
  • 35
  • 8
  • 3
    so what's your problem? – Abu Sufian Jan 02 '20 at 10:29
  • 2
    You have to differentiate between the double and its data structure and the visual representation of that data. You cannot change the first. but you can change the second: https://stackoverflow.com/questions/16098046/how-do-i-print-a-double-value-without-scientific-notation-using-java – OH GOD SPIDERS Jan 02 '20 at 10:33
  • Both 719379705 and 7.19379705E8 are the **same** value, just different presentation. – Mark Rotteveel Jan 02 '20 at 15:27

1 Answers1

5

The value being returned is a valid double, and the E denotes exponential. You do not have to worry about what is being returned inside a double as long as it is a valid double value.

If you need a formatted double value, and not for the computation, I'd suggest you to rather stick to the String.

Even after that, if you just don't like a double value with an exponential, you can rather use the BigDecimal.

return BigDecimal.valueOf(valeur);

I hope this makes sense.

deHaar
  • 17,687
  • 10
  • 38
  • 51
Safeer Ansari
  • 772
  • 4
  • 13