Answers for "does decimalformat java round the decimal places"

3

decimal up to 6 places in java

double num = 1.34567;
System.out.format("%.4f", num);
Posted by: Guest on November-11-2020
0

round decimals in java string

package com.mkyong.math.rounding;

public class StringFormatExample {

  public static void main(String[] args) {

      double input = 1205.6358;

      System.out.println("salary : " + input);

      // round half-up, no way control
      // 1205.64
      System.out.println("salary : " + String.format("%.2f", input));

      // 1205.64
      System.out.format("salary : %.2f", input);

  }

}
Posted by: Guest on March-06-2022

Code answers related to "does decimalformat java round the decimal places"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language