Java examples for java.math:BigDecimal Format
format BigDecimal by scale and rounding
//package com.java2s; import java.math.BigDecimal; public class Main { public static void main(String[] argv) throws Exception { BigDecimal value = new BigDecimal("1234"); System.out.println(format(value)); }/*www . j ava 2 s. c o m*/ private static final int SCALE = 2; public static BigDecimal format(BigDecimal value) { if (value == null) return null; return value.setScale(SCALE, BigDecimal.ROUND_HALF_UP); } }