Here you can find the source of format(BigDecimal n, int prec)
public static BigDecimal format(BigDecimal n, int prec)
//package com.java2s; //License from project: Apache License import java.math.BigDecimal; public class Main { /**/*from w ww . j a va 2 s.c om*/ * Returns the BigDecimal value n with exactly 'prec' decimal places. Zeroes * are padded to the right of the decimal point if necessary. */ public static BigDecimal format(BigDecimal n, int prec) { return n.setScale(prec, BigDecimal.ROUND_HALF_UP); } }