Code example for BigDecimal

Methods: compareTo, toPlainString

0
public class Util { 
	 
	public static boolean isValidBitcoinAmount(BigDecimal amount) {
		 
		// negative? 
		if (amount.compareTo(new BigDecimal("0")) == -1)
			return false; 
		 
		// exceeding the maximum money supply?  
		if (amount.compareTo(new BigDecimal("21000000")) == 1)
			return false; 
		 
		// too precise? 
		String[] bits = amount.toPlainString().split("\\.");
		if (bits.length == 2) {
			if (StringUtils.stripEnd(bits[1], "0").length() > 8) {
				return false; 
			} 
		} 
		 
		return true;