Compare the BigDecimal first to the int second. - Java java.math

Java examples for java.math:BigDecimal Compare

Description

Compare the BigDecimal first to the int second.

Demo Code


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

public class Main {
    public static void main(String[] argv) throws Exception {
        BigDecimal first = new BigDecimal("1234");
        int second = 2;
        System.out.println(compare(first, second));
    }//ww w.jav  a2  s.  c  o m

    /**
     * Compare the BigDecimal first to the int second.
     * 
     * @param first
     *                first number to compare
     * @param second
     *                second number to compare
     * @return a negative value, 0, or a positive value as this BigDecimal
     *         is numerically less than, equal to, or greater than val.
     */
    public static int compare(final BigDecimal first, final int second) {
        return first.compareTo(new BigDecimal(second));
    }
}

Related Tutorials