List of utility methods to do BigDecimal
BigDecimal | getBtcToBuy(BigDecimal ask, BigDecimal bid, BigDecimal fee, BigDecimal scalpAmount) Get the amount of BTC that needs to be bought after selling the scalpped amount: x = A*N*(1-F) / B Where: A = Ask N = Scalp amount F = Transaction fees B = Bid BigDecimal one = new BigDecimal(1); BigDecimal oneMinusFee = one.subtract(fee); BigDecimal btcToBuy = ask.multiply(scalpAmount).multiply(oneMinusFee).divide(bid, 8, RoundingMode.FLOOR); return btcToBuy; |
byte[] | getByteArrayFromBigDecimalArray(Object value) Convert an instance of our value class into a byte[]. if (value == null) { return null; BigDecimal[] a = (BigDecimal[]) value; byte[] total = new byte[a.length * TOTAL_BYTES]; int index = 0; for (int i = 0; i < a.length; i++) { System.arraycopy(new byte[] { (byte) a[i].signum() }, 0, total, index, NR_SIGNAL_BYTES); ... |
BigDecimal | getConversionUsdBased(final String destinycode, final BigDecimal amount, final BigDecimal usdBasedBaseRate, BigDecimal usdBasedDestinyRate) get Conversion Usd Based if (destinycode.equals("USD")) { return amount.multiply(usdBasedDestinyRate); } else { BigDecimal inverted = BigDecimal.ONE.divide(usdBasedBaseRate, 2, RoundingMode.HALF_UP); BigDecimal baseRatio = usdBasedDestinyRate.multiply(inverted); return amount.multiply(baseRatio); |
Date | getDateFromRank(BigDecimal rank) get Date From Rank return new Date(rank.negate().scaleByPowerOfTen(3).longValue()); |
BigDecimal | getDepositAmount(Boolean isReceipt, BigDecimal amount) get Deposit Amount BigDecimal deposit = BigDecimal.ZERO; if (isReceipt) { if (amount.compareTo(BigDecimal.ZERO) == 1) { deposit = amount; } else { if (amount.compareTo(BigDecimal.ZERO) == -1) { deposit = amount.abs(); ... |
int | getDigits(BigDecimal value) get Digits String string = value.stripTrailingZeros().toPlainString(); int index = string.indexOf("."); int scale = index < 0 ? 0 : string.length() - index - 1; return scale; |
double | getDistance(BigDecimal sourceLatitude, BigDecimal sourceLongitude, BigDecimal destLatitude, BigDecimal destLongitude) This method takes the source latitude, longitude and destination latitude, longitude to calculate the distance between two points and returns the distance double distance = 0.0; double diffOfLat = Math.toRadians(destLatitude.doubleValue() - sourceLatitude.doubleValue()); double diffOfLon = Math.toRadians(destLongitude.doubleValue() - sourceLongitude.doubleValue()); double sourceLatRad = Math.toRadians(sourceLatitude.doubleValue()); double destLatRad = Math.toRadians(destLatitude.doubleValue()); double calcResult = Math.sin(diffOfLat / 2) * Math.sin(diffOfLat / 2) + Math.cos(sourceLatRad) * Math.cos(destLatRad) * Math.sin(diffOfLon / 2) * Math.sin(diffOfLon / 2); calcResult = 2 * Math.atan2(Math.sqrt(calcResult), Math.sqrt(1 - calcResult)); ... |
BigDecimal | getDividedBigDecimal(final int nDividend, final int nDivisor) Get the division result using BigDecimal . final BigDecimal aDividend = BigDecimal.valueOf(nDividend); final BigDecimal aDivisor = BigDecimal.valueOf(nDivisor); return aDividend.divide(aDivisor); |
double | getDoubleBigDecimal(String amount, int afterDot) get Double Big Decimal double result = 0; BigDecimal bigDecimal = new BigDecimal(amount); result = bigDecimal.setScale(afterDot, BigDecimal.ROUND_HALF_EVEN).doubleValue(); return result; |
Date | getEndTimeByManDay(Date serviceStartTime, BigDecimal manDay) get End Time By Man Day if (serviceStartTime == null) { return null; Calendar startTime = Calendar.getInstance(); startTime.setTime(serviceStartTime); startTime.set(Calendar.MINUTE, 0); startTime.set(Calendar.SECOND, 0); startTime.set(Calendar.MILLISECOND, 0); ... |