Yes you can do it with String.format
:
String result = String.format("%.2f", 10.0 / 3.0);
// result: "3.33"
result = String.format("%.3f", 2.5);
// result: "2.500"
More Related Contents:
- Double decimal formatting in Java
- Heavy numbers calculation in Java
- Change date format in a Java string
- How can I pad an integer with zeros on the left?
- Convert Date/Time for given Timezone – java
- Moving decimal places over in a double
- How can I convert byte size into a human-readable format in Java?
- How to round a number to n decimal places in Java
- Format double value in scientific notation
- Newline in JLabel
- Java output formatting for Strings
- How can I calculate a time span in Java and format the output?
- How to format a Java string with leading zero?
- How to convert current date into string in java?
- How to format LocalDate object to MM/dd/yyyy and have format persist
- Converting Decimal to Binary Java
- Print out elements from an array with a comma between elements except the last word
- formatting a string to a currency format in jasper report
- Sprintf equivalent in Java
- Show padding zeros using DecimalFormat
- Java – format double value as dollar amount
- StAX XML formatting in Java
- Java round to nearest .5 [duplicate]
- Print out elements from an Array with a Comma between the elements
- Adding binary numbers
- Generate fixed length Strings filled with whitespaces
- In Java how do you convert a decimal number to base 36?
- How to use String.format() in Java? [duplicate]
- Java printf using variable field size?
- Force point (“.”) as decimal separator in java