Code example for BigDecimal

Methods: doubleValue, scale

0
	 */ 
	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;
				} 
			}else{ 
				//double float 
				return big.doubleValue();
			} 
		}else{ 
			return comp;
		}