Code example for DecimalFormat

Methods: setDecimalSeparatorAlwaysShownformat

0
package com.daxia.hr.util; 
 
import java.math.BigDecimal; 
import java.text.DecimalFormat; 
 
public class DoubleUtils { 
	 
	public static double format(Double num) {
		DecimalFormat format = new DecimalFormat("0.00");
		format.setDecimalSeparatorAlwaysShown(true);
		if (num == null) {
			num = 0d;
		} 
		String str = format.format(num);
		/* BigDecimal big=new BigDecimal(num); 
		    System.out.println(big); 
		    System.out.println(big.setScale(100,2));*/ 
//		   return big.doubleValue();  
		 return Double.parseDouble(str);
	} 
	 
	public static double round(double value, int scale, int roundingMode) {   
       BigDecimal bd = new BigDecimal(value + "");   
       bd = bd.setScale(scale, roundingMode);