Use a DecimalFormatter:
double number = 0.9999999999999; DecimalFormat numberFormat = new DecimalFormat("#.00"); System.out.println(numberFormat.format(number));
Will give you “0.99”. You can add or subtract 0 on the right side to get more or less decimals.
Or use ‘#’ on the right to make the additional digits optional, as in with #.## (0.30) would drop the trailing 0 to become (0.3).
Related Posts:
- How do I limit the number of decimals printed for a double?
- How do I convert a String to an int in Java?
- Java – Convert integer to string [duplicate]
- Convert String to double in Java
- How can I convert a char to int in Java? [duplicate]
- Convert int to char in java
- “int cannot be dereferenced” in Java
- Converting double to integer in Java
- Java JDK – possible lossy conversion from double to int
- Round a double to 2 decimal places [duplicate]
- Round a double to 2 decimal places [duplicate]
- How can I prevent java.lang.NumberFormatException: For input string: “N/A”?
- Round a double to 2 decimal places
- Double array initialization in Java
- How to check if an int is a null
- How to check whether a int is not null or empty?
- What is the difference between Integer and int in Java?
- Double decimal formatting in Java
- Double cannot be dereferenced?
- How to implement infinity in Java?
- How can I truncate a double to only two decimal places in Java?
- Java double.MAX_VALUE?
- How can I truncate a double to only two decimal places in Java?
- Java, Simplified check if int array contains int
- JAVA Variable declaration not allowed here
- Java Array Sort descending?
- What do F and D mean at the end of numeric literals?
- Determine if a String is an Integer in Java [duplicate]
- Convert boolean to int in Java
- Java ArrayList of Doubles
- How to Convert Int to Unsigned Byte and Back
- Java – Change int to ascii
- What is the difference between “Double” and “double” in Java?
- Convert float to double without losing precision
- Convert double to float in Java
- Search for words with telephone numbers from 2-3-4 tree
- Java 8 Iterable.forEach() vs foreach loop
- How to round a number to n decimal places in Java
- Error unable to access jarfile C:\Jar
- In laymans terms, what does ‘static’ mean in Java? [duplicate]
- How can I use pointers in Java?
- JavaFX – Exception in Application start method?
- Is there a stopwatch in Java?
- com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
- Why is there no SortedList in Java?
- How to convert any Object to String?
- Java says FileNotFoundException but file exists
- Why am I getting InputMismatchException?
- Java integer list
- How can I properly compare two Integers in Java?
- element not interactable exception in selenium web automation
- How to override compareTo (Java)
- Why do I get an UnsupportedOperationException when trying to remove an element from a List?
- java.util.NoSuchElementException: No line found
- How to parse JSON in Java
- Declaring an unsigned int in Java
- Converting Hexadecimal String to Decimal Integer
- LocalDate to java.util.Date and vice versa simplest conversion?
- Uri not Absolute exception getting while calling Restful Webservice
- Very Basic Java
- SQLRecoverableException: I/O Exception: Connection reset
- What exactly is a Maven Snapshot and why do we need it?
- How to check if my string is equal to null?
- what is Ljava.lang.String;@
- “Could not find Java SE Runtime Environment.” after installing Java
- How can I create an utility class?
- difference between ‘static int’ and ‘int’ in java
- How to use PrintWriter and File classes in Java?
- Error message “unreported exception java.io.IOException; must be caught or declared to be thrown”
- Proxy Error 502 : The proxy server received an invalid response from an upstream server
- how to do a system pause in java for debugging?
- Immutable class?
- Is spring default scope singleton or not?
- Java Reflection – Object is not an instance of declaring class
- What does “AL lib: alc_cleanup: 1 device not closed” mean?
- Java Enum return Int
- break statement in “if else” – java
- What is the difference between JSF, Servlet and JSP?
- Get only part of an Array in Java?
- How to Get JSON Array Within JSON Object?
- What is a class constant?
- How to represent a fix number of repeats in regular expression?
- How to import a jar in Eclipse
- Resolving File paths – ‘File not found’ error in Eclipse
- Simple Coin Toss using random class in Java. The do while loop doesn’t seem to generate random results
- Why I am getting DefaultHttpClient is deprecated?
- When should you use multithreading? And would multi threading be beneficial if the different threads execute mutually independent tasks?
- Suggestions needed: Effective Java to C source code converter
- Downloading a file from spring controllers
- Java Error Exception in thread “AWT-EventQueue-0” java.lang.StackOverflowError
- Write a program that reads an unspecified number of integers, determines pos, neg, total, average
- MessageBodyWriter not found for media type=application/json
- Conversion from Long to Double in Java
- Failed to find Java VM
- Java regex email
- Java Iterator on Doubly-linked-list
- Why “no projects found to import”?
- Java Swing setting JPanel Size
- how to use “tab space” while writing in text file
- Change Name of Import in Java, or import two classes with the same name