1

I have a division 4/3 which produces 1.33333333... I am storing the result in java double and I want to round this result to 1.34. How can this be done in Java ?

import java.text.*;
import java.math.RoundingMode;
public class HelloWorld{

     public static void main(String []args){


     DecimalFormat decimalFormat = new DecimalFormat("#.##");
     decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
      String dd =decimalFormat.format(1.33333333);
      System.out.println(dd);
     }
}

Works with (Math.ceil(1.333333 * 100) / 100.0) but not with DecimalFormat

0 Answers0