Here you can find the source of compareTo(Object val1, Object val2)
public static int compareTo(Object val1, Object val2)
//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 }