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 OverflowGeeksforGeeks
geeksforgeeks.org › java › double-parsedouble-method-in-java-with-examples
Double parseDouble() method in Java with examples - GeeksforGeeks
July 11, 2025 - // Java Code to implement // parseDouble() method of Double class class GFG { // Driver method public static void main(String[] args) { try { String str = ""; // returns the double value // represented by the string argument double val = Double.pa...
Tutorialspoint
tutorialspoint.com › home › java/lang › java double parsedouble method
Java Double parseDouble Method
September 1, 2008 - Following is the declaration for java.lang.Double.parseDouble() method · public static double parseDouble(String s) throws NumberFormatException ... This method returns the double value represented by the string argument.
Videos
How To Convert String To Double In Java - YouTube
03:14
String to double conversion in java | Convert String to double ...
01:47
Convert string to double in java using 2 ways | String to Double ...
How to convert String to double in Java | Java Convert String ...
Top answer 1 of 15
520
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 15
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(",",".") );
Stack Overflow
stackoverflow.com › questions › 72652140 › i-want-to-parse-a-string-and-get-a-double-value-java
I want to parse a string and get a double value (java) - Stack Overflow
String myString = "65.2 hello"; double value = Double.parseDouble(myString.replaceAll("[^(-?\\d+(\\.\\d+)?)]", "").trim()); should be suffice. But, if there is more than one numerical value within the string then you would need to change it ...
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Double.html
Double (Java Platform SE 8 )
October 20, 2025 - Constructs a newly allocated Double object that represents the floating-point value of type double represented by the string. The string is converted to a double value as if by the valueOf method. ... NumberFormatException - if the string does not contain a parsable number.
DigitalOcean
digitalocean.com › community › tutorials › java-convert-string-to-double
Java Convert String to double | DigitalOcean
August 3, 2022 - String str = "98.7"; double d = new Double(str).doubleValue(); //constructor deprecated in java 9 System.out.println(d); //98.7 · This is useful to parse formatted string to double. For example, if String is “1,11,111.23d” then we can use DecimalFormat to parse this string to double as:
Javatpoint
javatpoint.com › java-double-parsedouble-method
Java Double parseDouble() Method - Javatpoint
The parseDouble method of Java Double class returns a new double value that is initialized to the value corresponding to defined String.
BeginnersBook
beginnersbook.com › 2013 › 12 › how-to-convert-string-to-double-in-java
Java Convert String to Double examples
The value of variable dnum of double type would be 122.202 after conversion. Lets see the complete example of the conversion using parseDouble(String) method. public class JavaExample{ public static void main(String args[]){ String str = "122.202"; /* Convert String to double using * ...
Reddit
reddit.com › r/learnprogramming › [java] what's double.parsedouble and how do i go about using it?
r/learnprogramming on Reddit: [Java] What's Double.parseDouble and how do I go about using it?
October 24, 2012 -
If you can explain in terms of C++ too, it would help in me understanding it better.
Top answer 1 of 2
4
Double.parseDouble converts a string into a double, or throws a NumberFormatException if the string does not represent a double. e.g. Double.parseDouble("3.14") returns the double 3.14. All of Java's numeric types have a corresponding parse function that takes a string and returns its numeric value. e.g. Integer.parseInt("12345") returns the int 12345. This is similar to C++'s atof and atoi functions.
2 of 2
2
Was something unclear about the documentation?
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › lang › Double.html
Double (Java SE 17 & JDK 17)
January 20, 2026 - ... Deprecated, for removal: This API element is subject to removal in a future version. It is rarely appropriate to use this constructor. Use parseDouble(String) to convert a string to a double primitive, or use valueOf(String) to convert a string to a Double object.
Coderanch
coderanch.com › t › 595201 › java › parse-Double-parseDouble
What is parse? (Double.parseDouble();)? (Beginning Java forum at Coderanch)
This is an example he gave. I pasted the whole code just in case. public static void main(String[] args) { Scanner keyboard; keyboard = new Scanner(System.in); boolean userContinue = true; String userInput; int count = 0; double sum = 0; double average = 0; while (userContinue) { System.out.println("Enter a number or Q to quit"); userInput = keyboard.next(); if (userInput.toLowerCase().equals("q")) { userContinue = false; } else { sum += Double.parseDouble(userInput); count += 1; } } // end of the while average = sum / count; System.out.printf("The average is %f\n", average); } // end of main Thank you!!
IncludeHelp
includehelp.com › java › double-class-parsedouble-method-with-example.aspx
Java - Double Class parseDouble() Method
// Java program to demonstrate ... args) { // Variables initialization String str1 = "100"; String str2 = "6.7"; // Object initialization Double d1 = new Double(str2); // It convert string into double by calling parseDouble() method // and store the result in another variable ...
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....
GeeksforGeeks
geeksforgeeks.org › java › convert-string-to-double-in-java
Convert String to Double in Java - GeeksforGeeks
July 11, 2025 - The parseDouble() method of the ... as done by the valueOf method of class Double. ... Example: Java Program to Convert String to Double Using parseDouble() Method....
Baeldung
baeldung.com › home › java › java string › convert string to double in java
Convert String to Double in Java | Baeldung
January 8, 2024 - Since Java 5, this boxed Double is converted by the compiler to a primitive double where needed. In general, we should favor Double.parseDouble since it does not require the compiler to perform auto-unboxing. When a String representing a double has a more complex format, we can use a DecimalFormat. For example, we can convert a decimal-based currency value without removing non-numeric symbols:
Programiz
programiz.com › java-programming › examples › string-to-double-conversion
Java Program to convert string variables to double
For example, class Main { public static void main(String[] args) { // create a string variable String str1 = "Programiz"; // convert string to double // using parseDouble() double num1 = Double.parseDouble(str1); // print double values System.out.println(num1); // throws NumberFormatException } }
Java Tutorial HQ
javatutorialhq.com › java tutorial › java.lang › double › parsedouble(string s) method example
Java Double parseDouble(String s) method example
September 30, 2019 - This method returns the primitive double value of the string method input. To make this example sensible we will calculate the tax incurred from the user input. package com.javatutorialhq.java.examples; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; /* * This example source code demonstrates the use of static method * parseDouble(String str) of Double class */ public class DoubleParseDoublefString { public static void main(String[] args) { /* * Example on how to calculate the tax incurred * given the amount and tax percent