Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSS

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);

  }

}
Source by www.codegrepper.com #
 
PREVIOUS NEXT
Tagged: #decimals #java #string
ADD COMMENT
Topic
Name
3+4 =