Java Number Compare toPrimaryValue(Comparable comp)

Here you can find the source of toPrimaryValue(Comparable comp)

Description

to Primary Value

License

Apache License

Declaration

public static Comparable<?> toPrimaryValue(Comparable<?> comp) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.math.BigDecimal;

public class Main {

    public static Comparable<?> toPrimaryValue(Comparable<?> comp) {

        if (comp instanceof BigDecimal) {
            BigDecimal big = (BigDecimal) comp;
            int scale = big.scale();
            if (scale == 0) {
                // long int
                try {
                    return big.longValueExact();
                } catch (ArithmeticException e) {
                    return big;
                }//from   w w w  .  j ava2  s  . c  o m
            } else {
                // double float
                return big.doubleValue();
            }
        } else {
            return comp;
        }

    }
}

Related

  1. compareTwoObject(Object o1, Object o2)
  2. compareValue(Object left, Object right)
  3. compareValues(String value, String type, Object obj)
  4. getCrosstabRowColumnValue(String groupIdentifier, Map crosstabInfoMap, Object executorUnitId, String financesBankId, String companyNumber, String accountNumber)
  5. getDifficulty(long compactTarget)