Languages
[Edit]
EN

Java - convert String to double

1 points
Created by:
Root-ssh
178180

In Java, we can convert String to double in couple of different ways.

Short solutions:

1. Using Double.parseDouble()

Edit

Output:

When we use Double.parseDouble() we can use +, - as prefix. Also we can use d or D as postfix. Below we have practical example.

2. Using Double.valueOf()

Edit

Output:

3. Using constructor - new Double(String s)

Edit

Output:

4. Using DecimalFormat parse method

Edit

Output:

5. Using sun.misc.FloatingDecimal.parseDouble()

Edit

 Output:

NOTE:
When we look under the hood of:
- Double.parseDouble("123.45")
- Double.valueOf("123.45")
- new Double("123.45")
Then we can see that all of those methods call:
sun.misc.FloatingDecimal.parseDouble()

Reference

Edit
  1. Type conversion - wiki
  2. Double.parseDouble() - docs
  3. Double.valueOf() - docs
  4. new Double() - docs
  5. DecimalFormat parse() - docs
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Java - String conversion

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join