Java Number Compare compareTo(Object val1, Object val2)

Here you can find the source of compareTo(Object val1, Object val2)

Description

compare To

License

Open Source License

Declaration

public static int compareTo(Object val1, Object val2) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.math.BigDecimal;

public class Main {
    public static final int ROUNDING_MODE = BigDecimal.ROUND_HALF_UP;
    public static final int COMPARE_SCALE = 2;

    public static int compareTo(Object val1, Object val2) {
        return new BigDecimal(val1.toString()).setScale(COMPARE_SCALE, ROUNDING_MODE)
                .compareTo(new BigDecimal(val2.toString()).setScale(COMPARE_SCALE, ROUNDING_MODE));
    }// w  ww  . jav  a2  s.  c  o m
}

Related

  1. compare(Object o1, Object o2)
  2. compareDoubleAgainstLong(double lhs, long rhs)
  3. compareDoublesWithTolerance(double aa, double bb, double tolerance)
  4. compareStringsAsNumbers(String s1, String s2, String op)
  5. compareTo(double v1, double v2)
  6. compareTo(Object value1, Object value2)
  7. compareTwoObject(Object o1, Object o2)
  8. compareValue(Object left, Object right)
  9. compareValues(String value, String type, Object obj)