You can use Double.parseDouble() to convert a String to a double:
String text = "12.34"; // example String
double value = Double.parseDouble(text);
For your case it looks like you want:
double total = Double.parseDouble(jlbTotal.getText());
double price = Double.parseDouble(jlbPrice.getText());
Answer from WhiteFang34 on Stack Overflow Top answer 1 of 13
519
You can use Double.parseDouble() to convert a String to a double:
String text = "12.34"; // example String
double value = Double.parseDouble(text);
For your case it looks like you want:
double total = Double.parseDouble(jlbTotal.getText());
double price = Double.parseDouble(jlbPrice.getText());
2 of 13
57
If you have problems in parsing string to decimal values, you need to replace "," in the number to "."
String number = "123,321";
double value = Double.parseDouble( number.replace(",",".") );
How To Convert String To Double In Java - YouTube
01:47
Convert string to double in java using 2 ways | String to Double ...
01:21
How to Convert a Double to a String in Java Without Using Scientific ...
01:44
Best Practice for Converting a Double to a String in Java - YouTube
04:01
double to String conversion in java | Java Convert double to String ...
03:14
String to double conversion in java | Convert String to double ...
BeginnersBook
beginnersbook.com › 2013 › 12 › how-to-convert-string-to-double-in-java
Java Convert String to Double examples
September 11, 2022 - There are three ways to convert String to double. 1. Java – Convert String to Double using Double.parseDouble(String) method 2. Convert String to Double in Java using Double.valueOf(String) 3.
Codemia
codemia.io › home › knowledge hub › convert string to double in java
Convert String to double in Java | Codemia
January 26, 2025 - It is fast, simple, and correct for normal Java-style numeric text such as "3.14" or "1e6". The real challenge is not the conversion itself. It is deciding what should happen when the input is invalid, locale-specific, or too precise for binary floating-point. ... 1public class ParseDoubleExample { 2 public static void main(String[] args) { 3 String text = "23.456"; 4 double value = Double.parseDouble(text); 5 System.out.println(value); 6 } 7}
Vultr Docs
docs.vultr.com › java › examples › convert string variables to double
Java Program to convert string variables to double | Vultr Docs
December 20, 2024 - Use DecimalFormat to handle these cases and parse strings into doubles according to locale-specific rules. ... import java.text.DecimalFormat; import java.text.ParseException; String euroNumberStr = "1.234,56"; DecimalFormat format = new DecimalFormat("#,##0.00"); try { double number = format.parse(euroNumberStr).doubleValue(); System.out.println(number); } catch (ParseException e) { System.out.println("Number format error: " + e.getMessage()); }
Java Guides
javaguides.net › 2018 › 08 › java-convert-string-to-double-example.html
Convert String To Double in Java
June 15, 2024 - The DecimalFormat class allows you to parse a string into a double using a specific pattern. import java.text.DecimalFormat; import java.text.ParseException; public class StringToDoubleUsingDecimalFormat { public static void main(String[] args) { String strValue = "1234.56"; // Convert string to double using DecimalFormat DecimalFormat decimalFormat = new DecimalFormat("#.##"); try { double doubleValue = decimalFormat.parse(strValue).doubleValue(); System.out.println("String value: " + strValue); System.out.println("Double value: " + doubleValue); } catch (ParseException e) { e.printStackTrace(); } } }
Mkyong
mkyong.com › home › java › java – convert string to double
Java – Convert String to double | mkyong.com
May 3, 2019 - In Java, we can use Double.parseDouble() to convert a String to double · Example to convert a String 3.142 to an primitive double. String str = "3.142"; double pi = Double.parseDouble(str); System.out.println(pi); Output · 3.142 · Example ...
Java67
java67.com › 2015 › 06 › how-to-convert-string-to-double-java-example.html
How to convert String to Double in Java and double to String with Example | Java67
Just make sure that empty String literal i.e. "" should be the first argument or else + operator will do addition instead of String concatenation. The second method is mainly for the Double objects, but don't worry even if you have a double value you can leverage autoboxing to first convert it into a Double object and then just call the toString() method on it to get an equivalent String in Java.
Blogger
javahungry.blogspot.com › 2019 › 01 › convert-String-to-double-in-java.html
5 ways : How to Convert from String to double in Java | Java Hungry
public class StringToDouble { public ... doubleNum); } } Output : Convert String to double 1011.99 · The class java.text.DecimalFormat parse(String str) method can be used to convert String to double....
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Double.html
Double (Java Platform SE 8 )
July 21, 2026 - Java™ Platform Standard Ed. 8 ... The Double class wraps a value of the primitive type double in an object. An object of type Double contains a single field whose type is double. In addition, this class provides several methods for converting a double to a String and a String to a double, as well as other constants and methods useful when dealing with a double.
JavaMadeSoEasy
javamadesoeasy.com › 2016 › 03 › how-to-convert-string-to-double-and.html
JavaMadeSoEasy.com (JMSE): How to convert String to double and double to string in java
In this core java tutorial we will learn how to convert String to double primitive type in java and convert String to double object with program and examples in java.
WsCube Tech
wscubetech.com › resources › java › programs › string-to-double
Convert String to Double in Java (4 Programs)
September 16, 2026 - Learn 4 simple ways to convert a String to Double in Java. Explore examples using Double.parseDouble(), valueOf(), Scanner methods, and more. Read now!
Edureka Community
edureka.co › home › community › categories › java › string to double conversion in java
String to Double conversion in java | Edureka Community
April 14, 2018 - How can I convert a String such as "123.456" to a double in Java?