reverse +,- sign BigDecimal. - Java java.math

Java examples for java.math:BigDecimal

Description

reverse +,- sign BigDecimal.

Demo Code


//package com.java2s;
import java.math.BigDecimal;

public class Main {
    public static void main(String[] argv) throws Exception {
        BigDecimal decimal = new BigDecimal("1234");
        System.out.println(reverseSign(decimal));
    }//from w w  w .j  a  va2  s .c  om

    /**
     * The value -1, with a scale of 0.
     */
    public static final BigDecimal MINUS_ONE = BigDecimal.valueOf(-1L);

    /**
     * reverse +,- sign.
     *
     * @see #minus(BigDecimal)
     */
    public static BigDecimal reverseSign(BigDecimal decimal) {
        return minus(decimal);
    }

    /**
     * decimal * -1;
     *
     * @param decimal decimal
     * @return decimal * -1
     */
    public static BigDecimal minus(BigDecimal decimal) {
        return decimal.multiply(MINUS_ONE);
    }
}

Related Tutorials