Java BigDecimal stripTrailingZeros(final BigDecimal decimal)

Here you can find the source of stripTrailingZeros(final BigDecimal decimal)

Description

Strips trailing zeros from a BigDecimal.

License

Open Source License

Parameter

Parameter Description
decimal the big decimal to strip, not null

Return

the stripped decimal, not null

Declaration

public static BigDecimal stripTrailingZeros(final BigDecimal decimal) 

Method Source Code

//package com.java2s;
/**/*from   www .  j  a va2s  .c  o m*/
 * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */

import java.math.BigDecimal;

public class Main {
    /** Singleton zero. */
    private static final BigDecimal ZERO = BigDecimal.valueOf(0, 0);

    /**
     * Strips trailing zeros from a BigDecimal.
     * <p>
     * The JDK does not strip zeros from zero.
     * <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6480539">Bug 6480539</a>.
     * 
     * @param decimal  the big decimal to strip, not null
     * @return the stripped decimal, not null
     */
    public static BigDecimal stripTrailingZeros(final BigDecimal decimal) {
        if (decimal.compareTo(ZERO) == 0) {
            return ZERO;
        } else {
            return decimal.stripTrailingZeros();
        }
    }
}

Related

  1. Str2BigDecimal(String a)
  2. str2BigDicimal(String strbigdecimal)
  3. stripAndOrRescale(BigDecimal value)
  4. stripTrailingZeros(BigDecimal bigDecimal)
  5. stripTrailingZeros(BigDecimal value)
  6. strToBigDecimal(final String arg)
  7. strValueBigDecimal(Number number)
  8. tangent(BigDecimal x)
  9. tanto(BigDecimal r, BigDecimal n)