How can I convert a String
such as "12.34"
to a double
in Java?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
This should convert the string aString into the double d.
You only need to parse String values using Double
Use
new BigDecimal(string)
. This will guarantee proper calculation later.As a rule of thumb - always use
BigDecimal
for sensitive calculations like money.Example:
This is what I would do
For example you input the String "4 55,63. 0 " the output will the double number 45563.0
There is another way too.
Double is a class and "temp" is a variable. "number" is the final number you are looking for.