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 do i convert double to string?
char string[20]; double d = 3.1415926; snprintf(buffer, 20, "%f", d); More on reddit.com
How to format doubles converted to a string?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
How to convert string to double without losing precision after decimal point?
The short answer is that you can’t. The long answer is that 5.0 and 5.00000 are the same thing. Internally double has more precision, but when you print a double it only prints with the amount of precision you need. The answer is to print the decimal with a format string as shown in the second line below. Double number = Double.parseDouble(“5.00000”); System.out.printf(“%.5f”, number); That second line says print a formatted string, % means print a variable, .5 means print 5 decimal places, f means the variable is floating point, and number is just the variable that stores your number. More on reddit.com
java.lang.string cannot be converted to double
Without a code example, it's more or less impossible to debug. But before asking for help, I strongly suggest trying to figure this one out yourself. Think, what is the error message saying? What does that imply? More on reddit.com
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.
Javadeveloper
javadeveloper.io › blog › java › 2022 › string-to-double.html
How To Convert String to double Java? - JavaDeveloper.IO
January 20, 2022 - double myNumber; try { myNumber = Double.parseDouble(theString); } catch (NumberFormatException e) { System.out.println("Failed to convert String to double"); } NumberFormatException will be thrown if your String cannot be converted to 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?