Here you can find the source of trim(BigDecimal n)
public static BigDecimal trim(BigDecimal n)
//package com.java2s; //License from project: Apache License import java.math.BigDecimal; public class Main { /**//from ww w .j av a2s . co m * Returns the BigDecimal value n with trailing zeroes removed. */ public static BigDecimal trim(BigDecimal n) { try { while (true) { n = n.setScale(n.scale() - 1); } } catch (ArithmeticException e) { // no more trailing zeroes so exit. } return n; } }