Java BigDecimal Trim trim(BigDecimal n)

Here you can find the source of trim(BigDecimal n)

Description

Returns the BigDecimal value n with trailing zeroes removed.

License

Apache License

Declaration

public static BigDecimal trim(BigDecimal n) 

Method Source Code


//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;
    }
}

Related

  1. trim(BigDecimal pNombre)
  2. trim(BigDecimal val)
  3. trimBigDecimal(BigDecimal n)
  4. truncateAmount(BigDecimal value)