One of the way would be using NumberFormat.
NumberFormat formatter = new DecimalFormat("#0.00");
System.out.println(formatter.format(4.0));
Output:
4.00
More Related Contents:
- Moving decimal places over in a double
- Java – format double value as dollar amount
- Java decimal formatting using String.format?
- Force point (“.”) as decimal separator in java
- Heavy numbers calculation in Java
- Type mismatch: cannot convert from double to double[]
- How to compare BigInteger with double
- Change date format in a Java string
- How can I pad an integer with zeros on the left?
- Round a double to 2 decimal places [duplicate]
- Convert String to double in Java
- How can I convert byte size into a human-readable format in Java?
- Format double value in scientific notation
- Newline in JLabel
- Java output formatting for Strings
- In java, is it more efficient to use byte or short instead of int and float instead of double?
- How can I truncate a double to only two decimal places in Java?
- How do you test to see if a double is equal to NaN?
- How to convert current date into string in java?
- Convert double to BigDecimal and set BigDecimal Precision
- formatting a string to a currency format in jasper report
- How to implement infinity in Java?
- Show padding zeros using DecimalFormat
- StAX XML formatting in Java
- Double cannot be dereferenced?
- Java round to nearest .5 [duplicate]
- Double division behaving wrongly
- Adding and subtracting doubles are giving strange results [duplicate]
- Generate fixed length Strings filled with whitespaces
- Java: Double Value Comparison