Here you can find the source of removeTrailingZeros(final BigDecimal bd)
public static BigDecimal removeTrailingZeros(final BigDecimal bd)
//package com.java2s; /*//from w w w. j a va2 s . c o m * This program is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software * Foundation. * * You should have received a copy of the GNU Lesser General Public License along with this * program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html * or from the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * Copyright (c) 2006 - 2013 Pentaho Corporation and Contributors. All rights reserved. */ import java.math.BigDecimal; public class Main { public static BigDecimal removeTrailingZeros(final BigDecimal bd) { if (bd.signum() == 0) { return bd.setScale(0); } final String text = bd.toPlainString(); // get non-logarithm representation int scale = bd.scale(); for (int i = text.length() - 1; i >= 0; i--) { final char c = text.charAt(i); if (c != '0') { break; } scale -= 1; } return bd.setScale(scale); } }