double d34324.34

doesn't assign a value of 34324.34 but tries to declare a variable with the invalid name d4324.34 .

You probably wanted

double myDouble = 34324.34d;
long myLong = 34324l;
Answer from Denys Séguret on Stack Overflow
🌐
W3Schools
w3schools.com › java › ref_keyword_double.asp
Java double Keyword
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... The double keyword is a data type that can store fractional numbers from 1.7e−308 to 1.7e+308.
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Float-vs-Double-Whats-the-difference
Java double vs float: What's the difference?
If all of the values fall within the range of a float, it makes sense to use the smaller Java data type in this situation, otherwise the array elements needlessly consume memory. Data precision can be a problem with double and float types because binary numbers don’t always convert cleanly to decimals. For example, the following program prints out 11.3999 as the sum of 5.6 + 5.8:
Discussions

java - Double, float and long declaration - Stack Overflow
See this to learn about the valid variable names in java · Variable names can include any alphabetic character or digit and the underscore _. The main restriction on the names you can give your variables is that they cannot contain any white space. You cannot begin a variable name with a number. ... If the Value is whether flot or double to identigy the JVM using the number end with -d and -f. For example... More on stackoverflow.com
🌐 stackoverflow.com
Java doubles and 0.0
Does it do two checks if you do a zero comparison with a double? ... For pretty much everything that you try and fail, you can safely assume someone else tried and failed before, and wrote about it at the Internet. First hit was https://stackoverflow.com/questions/39933792/how-do-i-check-for-a-negative-zero-in-java... More on gamedev.net
🌐 gamedev.net
15
January 14, 2024
When should I use double and when should I use float for Java?
On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge. If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options: Limiting your involvement with Reddit, or Temporarily refraining from using Reddit Cancelling your subscription of Reddit Premium as a way to voice your protest. 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
🌐 r/learnprogramming
65
59
January 6, 2024
Print exact value of double
I put together an example for you that prints the raw storage bits. I think it covers most cases and should print the stored value as close as possible. For 0.3 it prints 0.29999999999999998889776975374843450 value = 0.3 encoded1 = (5404319552844595 / 4503599627370496) * 2^-2 encoded2 = 1.199999999999999955591079014993738 * 2^-2 result = 0.29999999999999998889776975374843450 import java.math.BigDecimal; import java.math.MathContext; public class DoublePrinter { public static void main(String[] args) { // see https://en.wikipedia.org/wiki/Double-precision_floating-point_format // a double is stored as sign * significand * 2^(exp-1023) double value = 0.3; long bits = Double.doubleToLongBits(value); // the sign is stored in the upmost bit, same as long long sign = Long.signum(bits); // first bit long exponentBits = (bits & EXP_BIT_MASK) >>> 52; // next 11 bits long significandBits = bits & SIGNIF_BIT_MASK; // lowest 52 // add the implicit leading bit if not subnormal if (exponentBits != 0) { significandBits |= 0x10000000000000L; } // map to a more readable represenation (significand is stored as (value / 1L<<52)) long divisor = 1L << 52; int exponent = (int) (exponentBits - 1023); // compute result using BigDecimal var mc = MathContext.DECIMAL128; BigDecimal significand = new BigDecimal(significandBits).divide(new BigDecimal(divisor), mc); BigDecimal scale = new BigDecimal(2).pow(exponent, mc); BigDecimal result = new BigDecimal(sign).multiply(significand).multiply(scale); System.out.println("value = " + value); System.out.println(String.format("encoded1 = %s(%d / %d) * 2^%d", sign < 0 ? "-" : "", significandBits, divisor, exponent)); System.out.println(String.format("encoded2 = %s%s * 2^%d", sign < 0 ? "-" : "", significand.toString(), exponent)); System.out.println("result = " + result); } final static long SIGN_BIT_MASK = 0x8000000000000000L; final static long EXP_BIT_MASK = 0x7FF0000000000000L; final static long SIGNIF_BIT_MASK = 0x000FFFFFFFFFFFFFL; } More on reddit.com
🌐 r/javahelp
16
3
January 7, 2024
🌐
DataCamp
datacamp.com › doc › java › double
double Keyword in Java: Usage & Examples
double negativeInfinity = Double.NEGATIVE_INFINITY; ... These constants can be used to handle special cases in floating-point arithmetic, such as results of undefined operations. Build your Java skills from the ground up and master programming concepts.
🌐
CodeGym
codegym.cc › java blog › java numbers › java double keyword
Java double keyword
February 19, 2025 - Java provides primitive data types like double for efficiency and simplicity. They aren’t objects, so they don’t come with object-oriented features. On the flip side, wrapper classes like Double wrap those primitive values in an object. That means you can store them in data structures that only accept objects, such as Collections. For example, a List<Double> can hold many doubles, but it can’t hold the primitive double.
🌐
Mkyong
mkyong.com › home › java › how to format a double in java
How to format a double in Java - Mkyong.com
July 23, 2020 - This example uses DecimalFormat to format a double; it also supports locale. ... package com.mkyong.io.utils; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.Locale; public class FormatDouble2 { public static void main(String[] args) { DecimalFormat df = new DecimalFormat("#,###.##"); // different locale - GERMAN DecimalFormat dfGerman = new DecimalFormat("#,###.##", new DecimalFormatSymbols(Locale.GERMAN)); String input = "1234567890.123456"; double d = Double.parseDouble(input); System.out.println(df.format(d)); // 1,234,567,890.12 System.out.println(dfGerman.format(d)); // 1.234.567.890,12 } }
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api
Double (Java Platform SE 8 )
October 20, 2025 - JavaScript is disabled on your browser · Frame Alert · This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to Non-frame version
Find elsewhere
🌐
BeginnersBook
beginnersbook.com › 2013 › 12 › how-to-convert-string-to-double-in-java
Java Convert String to Double examples
September 11, 2022 - 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 * ...
🌐
Baeldung
baeldung.com › home › java › java numbers › comparing doubles in java
Comparing Doubles in Java | Baeldung
December 11, 2025 - In this example, the two values d1 and d2 are considered equal up to one and two decimal places because they both round to 0.8 and 0.80, respectively, even though they differ slightly in binary representation.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-lang-double-class-java
Java.Lang.Double Class in Java - GeeksforGeeks
July 23, 2025 - ... // Java Program to Illustrate ... // double and String values double b = 55.05; String bb = "45"; // Construct two Double objects Double x = new Double(b); Double y = new Double(bb); // Method - toString() System.out....
🌐
GameDev.net
gamedev.net › forums › topic › 715430-java-doubles-and-00
Java doubles and 0.0 - For Beginners - GameDev.net
January 14, 2024 - You can read the basis of it for Java 21 here, but this specific behavior has been the same since the beginning of the language. Look down a few paragraphs to read “Positive zero and negative zero compare equal, so the result of the expression 0.0==-0.0 is true and the result of 0.0>-0.0 is false. Other operations can distinguish positive and negative zero; for example, 1.0/0.0 has the value positive infinity, while the value of 1.0/-0.0 is negative infinity.”
🌐
Quora
quora.com › How-do-I-convert-Object-to-double-in-Java
How to convert Object to double in Java - Quora
Answer (1 of 5): No one has touched on this yet, so I will: Stop using collections of [code ]Object[/code] to store dissimilar types. The reasons you’re facing this problem is you’re fighting against your tools. Collections are typed so that you always know for sure what they contain.
🌐
Medium
medium.com › @AlexanderObregon › javas-double-compare-method-explained-6159db37e326
Java’s Double.compare() Method Explained | Medium
December 23, 2024 - Although Double.compare() handles the ordering correctly, the underlying data might have accumulated rounding errors that affect downstream calculations. Example Scenario In financial or scientific applications where values range from extremely small to large, results might not align with expected accuracy:
🌐
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 - The argument is considered to be a representation of a floating-point value according to the IEEE 754 floating-point "double format" bit layout. If the argument is 0x7ff0000000000000L, the result is positive infinity. If the argument is 0xfff0000000000000L, the result is negative infinity.
🌐
Coderanch
coderanch.com › t › 428279 › java › converting-double
converting a double value (Beginning Java forum at Coderanch)
January 27, 2009 - I do know which is better - use the BigDecimal version. My rounding still gets flawed when there are some combinations of significantDigits and values getting passed into the methods. BigD seems to not have those problems. So go with isIntegerValue2(double input) and the asInt2(double input) ...
🌐
iO Flood
ioflood.com › blog › java-double
Java Double Keyword: Your Guide to Decimal Precision
February 26, 2024 - Here’s how you do it: double num1; // declaration num1 = 10.5; // initialization double num2 = 20.5; // declaration and initialization in the same line · In this example, we declare two ‘double’ variables, ‘num1’ and ‘num2’. ...
🌐
Baeldung
baeldung.com › home › java › java numbers › double precision issue in java
Double Precision Issue in Java | Baeldung
January 8, 2024 - Learn what the double precision issue is, how it affects code, and how to deal with it.
🌐
Tutorialspoint
tutorialspoint.com › home › java/lang › java double value method
Java Double Value Method
September 1, 2008 - Following is the syntax for Java Number doubleValue() method ... This method does not accept any parameters. This method returns the double value after conversion. The following example shows the usage of Java Number doubleValue() method. Here, we are instantiating an Integer object and initializing it.
🌐
Reddit
reddit.com › r/javahelp › print exact value of double
r/javahelp on Reddit: Print exact value of double
January 7, 2024 -

When I do

System.out.printf("%.50f", 0.3);

it outputs 0.30000000000000000000000000000000000000000000000000 but this can't be right because double can't store the number 0.3 exactly.

When I do the equivalent in C++

std::cout << std::fixed << std::setprecision(50) << 0.3;

it outputs 0.29999999999999998889776975374843459576368331909180 which makes more sense to me.

My question is whether it's possible to do the same in Java?

Top answer
1 of 4
2
I put together an example for you that prints the raw storage bits. I think it covers most cases and should print the stored value as close as possible. For 0.3 it prints 0.29999999999999998889776975374843450 value = 0.3 encoded1 = (5404319552844595 / 4503599627370496) * 2^-2 encoded2 = 1.199999999999999955591079014993738 * 2^-2 result = 0.29999999999999998889776975374843450 import java.math.BigDecimal; import java.math.MathContext; public class DoublePrinter { public static void main(String[] args) { // see https://en.wikipedia.org/wiki/Double-precision_floating-point_format // a double is stored as sign * significand * 2^(exp-1023) double value = 0.3; long bits = Double.doubleToLongBits(value); // the sign is stored in the upmost bit, same as long long sign = Long.signum(bits); // first bit long exponentBits = (bits & EXP_BIT_MASK) >>> 52; // next 11 bits long significandBits = bits & SIGNIF_BIT_MASK; // lowest 52 // add the implicit leading bit if not subnormal if (exponentBits != 0) { significandBits |= 0x10000000000000L; } // map to a more readable represenation (significand is stored as (value / 1L<<52)) long divisor = 1L << 52; int exponent = (int) (exponentBits - 1023); // compute result using BigDecimal var mc = MathContext.DECIMAL128; BigDecimal significand = new BigDecimal(significandBits).divide(new BigDecimal(divisor), mc); BigDecimal scale = new BigDecimal(2).pow(exponent, mc); BigDecimal result = new BigDecimal(sign).multiply(significand).multiply(scale); System.out.println("value = " + value); System.out.println(String.format("encoded1 = %s(%d / %d) * 2^%d", sign < 0 ? "-" : "", significandBits, divisor, exponent)); System.out.println(String.format("encoded2 = %s%s * 2^%d", sign < 0 ? "-" : "", significand.toString(), exponent)); System.out.println("result = " + result); } final static long SIGN_BIT_MASK = 0x8000000000000000L; final static long EXP_BIT_MASK = 0x7FF0000000000000L; final static long SIGNIF_BIT_MASK = 0x000FFFFFFFFFFFFFL; }
2 of 4
1
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.