Here are the examples of the java api class java.math.BigDecimal taken from open source projects.
1. SolarEventCalculator#getCosineSunLocalHour()
Project: sunrisesunsetlib-java
File: SolarEventCalculator.java
File: SolarEventCalculator.java
private BigDecimal getCosineSunLocalHour(BigDecimal sunTrueLong, Zenith zenith) { BigDecimal sinSunDeclination = getSinOfSunDeclination(sunTrueLong); BigDecimal cosineSunDeclination = getCosineOfSunDeclination(sinSunDeclination); BigDecimal zenithInRads = convertDegreesToRadians(zenith.degrees()); BigDecimal cosineZenith = BigDecimal.valueOf(Math.cos(zenithInRads.doubleValue())); BigDecimal sinLatitude = BigDecimal.valueOf(Math.sin(convertDegreesToRadians(location.getLatitude()).doubleValue())); BigDecimal cosLatitude = BigDecimal.valueOf(Math.cos(convertDegreesToRadians(location.getLatitude()).doubleValue())); BigDecimal sinDeclinationTimesSinLat = sinSunDeclination.multiply(sinLatitude); BigDecimal dividend = cosineZenith.subtract(sinDeclinationTimesSinLat); BigDecimal divisor = cosineSunDeclination.multiply(cosLatitude); return setScale(divideBy(dividend, divisor)); }
2. BigDecimalTest#test_equalsLjava_lang_Object()
Project: j2objc
File: BigDecimalTest.java
File: BigDecimalTest.java
/** * @tests java.math.BigDecimal#equals(java.lang.Object) */ public void test_equalsLjava_lang_Object() { BigDecimal equal1 = new BigDecimal(1.00D); BigDecimal equal2 = new BigDecimal("1.0"); assertFalse("1.00 and 1.0 should not be equal", equal1.equals(equal2)); equal2 = new BigDecimal(1.01D); assertFalse("1.00 and 1.01 should not be equal", equal1.equals(equal2)); equal2 = new BigDecimal("1.00"); assertFalse("1.00D and 1.00 should not be equal", equal1.equals(equal2)); BigInteger val = new BigInteger("100"); equal1 = new BigDecimal("1.00"); equal2 = new BigDecimal(val, 2); assertTrue("1.00(string) and 1.00(bigInteger) should be equal", equal1.equals(equal2)); equal1 = new BigDecimal(100D); equal2 = new BigDecimal("2.34576"); assertFalse("100D and 2.34576 should not be equal", equal1.equals(equal2)); assertFalse("bigDecimal 100D does not equal string 23415", equal1.equals("23415")); }
3. BTCEAdapters#adaptTicker()
Project: XChange
File: BTCEAdapters.java
File: BTCEAdapters.java
/** * Adapts a BTCETicker to a Ticker Object * * @param bTCETicker * @return */ public static Ticker adaptTicker(BTCETicker bTCETicker, CurrencyPair currencyPair) { BigDecimal last = bTCETicker.getLast(); BigDecimal bid = bTCETicker.getSell(); BigDecimal ask = bTCETicker.getBuy(); BigDecimal high = bTCETicker.getHigh(); BigDecimal low = bTCETicker.getLow(); BigDecimal avg = bTCETicker.getAvg(); BigDecimal volume = bTCETicker.getVolCur(); Date timestamp = DateUtils.fromMillisUtc(bTCETicker.getUpdated() * 1000L); return new Ticker.Builder().currencyPair(currencyPair).last(last).bid(bid).ask(ask).high(high).low(low).vwap(avg).volume(volume).timestamp(timestamp).build(); }
4. BTCChinaAdapters#adaptTicker()
Project: XChange
File: BTCChinaAdapters.java
File: BTCChinaAdapters.java
public static Ticker adaptTicker(BTCChinaTickerObject ticker, CurrencyPair currencyPair) { BigDecimal last = ticker.getLast(); BigDecimal high = ticker.getHigh(); BigDecimal low = ticker.getLow(); BigDecimal vwap = ticker.getVwap(); BigDecimal buy = ticker.getBuy(); BigDecimal sell = ticker.getSell(); BigDecimal volume = ticker.getVol(); Date date = adaptDate(ticker.getDate()); return new Ticker.Builder().currencyPair(currencyPair).last(last).high(high).low(low).vwap(vwap).bid(buy).ask(sell).volume(volume).timestamp(date).build(); }
5. BitstampAdapters#adaptTicker()
Project: XChange
File: BitstampAdapters.java
File: BitstampAdapters.java
/** * Adapts a BitstampTicker to a Ticker Object * * @param bitstampTicker The exchange specific ticker * @param currencyPair (e.g. BTC/USD) * @return The ticker */ public static Ticker adaptTicker(BitstampTicker bitstampTicker, CurrencyPair currencyPair) { BigDecimal last = bitstampTicker.getLast(); BigDecimal bid = bitstampTicker.getBid(); BigDecimal ask = bitstampTicker.getAsk(); BigDecimal high = bitstampTicker.getHigh(); BigDecimal low = bitstampTicker.getLow(); BigDecimal vwap = bitstampTicker.getVwap(); BigDecimal volume = bitstampTicker.getVolume(); Date timestamp = new Date(bitstampTicker.getTimestamp() * 1000L); return new Ticker.Builder().currencyPair(currencyPair).last(last).bid(bid).ask(ask).high(high).low(low).vwap(vwap).volume(volume).timestamp(timestamp).build(); }
6. BitMarketAdapters#adaptTicker()
Project: XChange
File: BitMarketAdapters.java
File: BitMarketAdapters.java
/** * Adapts BitMarket ticker to Ticker. * * @param bitMarketTicker * @param currencyPair * @return */ public static Ticker adaptTicker(BitMarketTicker bitMarketTicker, CurrencyPair currencyPair) { BigDecimal bid = bitMarketTicker.getBid(); BigDecimal ask = bitMarketTicker.getAsk(); BigDecimal high = bitMarketTicker.getHigh(); BigDecimal low = bitMarketTicker.getLow(); BigDecimal volume = bitMarketTicker.getVolume(); BigDecimal vwap = bitMarketTicker.getVwap(); BigDecimal last = bitMarketTicker.getLast(); return new Ticker.Builder().currencyPair(currencyPair).last(last).bid(bid).ask(ask).high(high).low(low).volume(volume).vwap(vwap).build(); }
7. EmpoExAdapters#adaptEmpoExTicker()
Project: XChange
File: EmpoExAdapters.java
File: EmpoExAdapters.java
public static Ticker adaptEmpoExTicker(EmpoExTicker raw) { CurrencyPair currencyPair = EmpoExUtils.toCurrencyPair(raw.getPairname()); BigDecimal last = new BigDecimal(raw.getLast().replace(",", "")); BigDecimal high = new BigDecimal(raw.getHigh().replace(",", "")); BigDecimal low = new BigDecimal(raw.getLow().replace(",", "")); BigDecimal bid = new BigDecimal(raw.getBid().replace(",", "")); BigDecimal ask = new BigDecimal(raw.getAsk().replace(",", "")); BigDecimal counterVolume = new BigDecimal(raw.getBaseVolume24hr().replace(",", "")); BigDecimal volume = counterVolume.divide(last, new MathContext(8, RoundingMode.HALF_UP)); return new Ticker.Builder().currencyPair(currencyPair).last(last).high(high).low(low).bid(bid).ask(ask).volume(volume).build(); }
8. SolarEventCalculator#getRightAscension()
Project: sunrisesunsetlib-java
File: SolarEventCalculator.java
File: SolarEventCalculator.java
/** * Computes the suns right ascension, RA in the algorithm, adjusting for the quadrant of L and turning it * into degree-hours. Will be in the range [0,360]. * * @param sunTrueLong * Suns true longitude, in <code>BigDecimal</code> * @return suns right ascension in degree-hours, in <code>BigDecimal</code> form. */ private BigDecimal getRightAscension(BigDecimal sunTrueLong) { BigDecimal tanL = new BigDecimal(Math.tan(convertDegreesToRadians(sunTrueLong).doubleValue())); BigDecimal innerParens = multiplyBy(convertRadiansToDegrees(tanL), new BigDecimal("0.91764")); BigDecimal rightAscension = new BigDecimal(Math.atan(convertDegreesToRadians(innerParens).doubleValue())); rightAscension = setScale(convertRadiansToDegrees(rightAscension)); if (rightAscension.doubleValue() < 0) { rightAscension = rightAscension.add(BigDecimal.valueOf(360)); } else if (rightAscension.doubleValue() > 360) { rightAscension = rightAscension.subtract(BigDecimal.valueOf(360)); } BigDecimal ninety = BigDecimal.valueOf(90); BigDecimal longitudeQuadrant = sunTrueLong.divide(ninety, 0, RoundingMode.FLOOR); longitudeQuadrant = longitudeQuadrant.multiply(ninety); BigDecimal rightAscensionQuadrant = rightAscension.divide(ninety, 0, RoundingMode.FLOOR); rightAscensionQuadrant = rightAscensionQuadrant.multiply(ninety); BigDecimal augend = longitudeQuadrant.subtract(rightAscensionQuadrant); return divideBy(rightAscension.add(augend), BigDecimal.valueOf(15)); }
9. SolarEventCalculator#computeSolarEventTime()
Project: sunrisesunsetlib-java
File: SolarEventCalculator.java
File: SolarEventCalculator.java
private BigDecimal computeSolarEventTime(Zenith solarZenith, Calendar date, boolean isSunrise) { date.setTimeZone(this.timeZone); BigDecimal longitudeHour = getLongitudeHour(date, isSunrise); BigDecimal meanAnomaly = getMeanAnomaly(longitudeHour); BigDecimal sunTrueLong = getSunTrueLongitude(meanAnomaly); BigDecimal cosineSunLocalHour = getCosineSunLocalHour(sunTrueLong, solarZenith); if ((cosineSunLocalHour.doubleValue() < -1.0) || (cosineSunLocalHour.doubleValue() > 1.0)) { return null; } BigDecimal sunLocalHour = getSunLocalHour(cosineSunLocalHour, isSunrise); BigDecimal localMeanTime = getLocalMeanTime(sunTrueLong, longitudeHour, sunLocalHour); BigDecimal localTime = getLocalTime(localMeanTime, date); return localTime; }
10. LoanTransactionData#LoanTransactionDataForDisbursalTemplate()
Project: incubator-fineract
File: LoanTransactionData.java
File: LoanTransactionData.java
public static LoanTransactionData LoanTransactionDataForDisbursalTemplate(final LoanTransactionEnumData transactionType, final LocalDate expectedDisbursedOnLocalDateForTemplate, final BigDecimal disburseAmountForTemplate, final Collection<PaymentTypeData> paymentOptions, final BigDecimal retriveLastEmiAmount, final LocalDate possibleNextRepaymentDate) { final Long id = null; final Long officeId = null; final String officeName = null; final PaymentDetailData paymentDetailData = null; final CurrencyData currency = null; final BigDecimal unrecognizedIncomePortion = null; final BigDecimal principalPortion = null; ; final BigDecimal interestPortion = null; final BigDecimal feeChargesPortion = null; final BigDecimal penaltyChargesPortion = null; final BigDecimal overpaymentPortion = null; final String externalId = null; final BigDecimal outstandingLoanBalance = null; final AccountTransferData transfer = null; final LocalDate submittedOnDate = null; final boolean manuallyReversed = false; return new LoanTransactionData(id, officeId, officeName, transactionType, paymentDetailData, currency, expectedDisbursedOnLocalDateForTemplate, disburseAmountForTemplate, principalPortion, interestPortion, feeChargesPortion, penaltyChargesPortion, overpaymentPortion, unrecognizedIncomePortion, paymentOptions, transfer, externalId, retriveLastEmiAmount, outstandingLoanBalance, submittedOnDate, manuallyReversed, possibleNextRepaymentDate); }
11. ChargeData#toShareAccountChargeData()
Project: incubator-fineract
File: ChargeData.java
File: ChargeData.java
public ShareAccountChargeData toShareAccountChargeData() { final Long shareChargeId = null; final Long shareAccountId = null; final BigDecimal amountPaid = BigDecimal.ZERO; final BigDecimal amountWaived = BigDecimal.ZERO; final BigDecimal amountWrittenOff = BigDecimal.ZERO; final BigDecimal amountOutstanding = BigDecimal.ZERO; final BigDecimal percentage = BigDecimal.ZERO; final BigDecimal amountPercentageAppliedTo = BigDecimal.ZERO; final Collection<ChargeData> chargeOptions = null; final Boolean isActive = null; final BigDecimal chargeAmountOrPercentage = BigDecimal.ZERO; return new ShareAccountChargeData(shareChargeId, this.id, shareAccountId, this.name, this.currency, this.amount, amountPaid, amountWaived, amountWrittenOff, amountOutstanding, this.chargeTimeType, this.chargeCalculationType, percentage, amountPercentageAppliedTo, chargeOptions, isActive, chargeAmountOrPercentage); }
12. BigDecimalTest#test_hashCode()
Project: j2objc
File: BigDecimalTest.java
File: BigDecimalTest.java
/** * @tests java.math.BigDecimal#hashCode() */ public void test_hashCode() { // anything that is equal must have the same hashCode BigDecimal hash = new BigDecimal("1.00"); BigDecimal hash2 = new BigDecimal(1.00D); assertTrue("the hashCode of 1.00 and 1.00D is equal", hash.hashCode() != hash2.hashCode() && !hash.equals(hash2)); hash2 = new BigDecimal("1.0"); assertTrue("the hashCode of 1.0 and 1.00 is equal", hash.hashCode() != hash2.hashCode() && !hash.equals(hash2)); BigInteger val = new BigInteger("100"); hash2 = new BigDecimal(val, 2); assertTrue("hashCode of 1.00 and 1.00(bigInteger) is not equal", hash.hashCode() == hash2.hashCode() && hash.equals(hash2)); hash = new BigDecimal(value, 2); hash2 = new BigDecimal("-1233456.0000"); assertTrue("hashCode of 123459.08 and -1233456.0000 is not equal", hash.hashCode() != hash2.hashCode() && !hash.equals(hash2)); hash2 = new BigDecimal(value.negate(), 2); assertTrue("hashCode of 123459.08 and -123459.08 is not equal", hash.hashCode() != hash2.hashCode() && !hash.equals(hash2)); }
13. VariationTestingClientStrategyTest#rangeTest()
Project: seldon-server
File: VariationTestingClientStrategyTest.java
File: VariationTestingClientStrategyTest.java
@Test public void rangeTest() { BigDecimal ratioTotal = new BigDecimal(1.0); BigDecimal currentMax = new BigDecimal(0.0); BigDecimal r1 = new BigDecimal(0.9); BigDecimal r2 = new BigDecimal(0.1); NumberRange range1 = new NumberRange(currentMax, currentMax.add(r1.divide(ratioTotal, 5, BigDecimal.ROUND_UP))); currentMax = currentMax.add(r1); NumberRange range2 = new NumberRange(currentMax.add(new BigDecimal(0.0001)), currentMax.add(r2.divide(ratioTotal, 5, BigDecimal.ROUND_UP))); BigDecimal t = new BigDecimal(0.900001); Assert.assertTrue(range1.containsNumber(t)); Assert.assertFalse(range2.containsNumber(t)); BigDecimal t2 = new BigDecimal(0.901); Assert.assertFalse(range1.containsNumber(t2)); Assert.assertTrue(range2.containsNumber(t2)); }
14. YacunaAdapters#adaptTicker()
Project: XChange
File: YacunaAdapters.java
File: YacunaAdapters.java
public static Ticker adaptTicker(YacunaTicker ticker, CurrencyPair currencyPair) { BigDecimal last = ticker.getOverallStatistics() != null && ticker.getOverallStatistics().getLastPricePair() != null ? ticker.getOverallStatistics().getLastPricePair().getAmount() : null; BigDecimal high = ticker.getDailyStatistics() != null && ticker.getDailyStatistics().getHighPricePair() != null ? ticker.getDailyStatistics().getHighPricePair().getAmount() : null; BigDecimal low = ticker.getDailyStatistics() != null && ticker.getDailyStatistics().getLowPricePair() != null ? ticker.getDailyStatistics().getLowPricePair().getAmount() : null; BigDecimal buy = ticker.getOverallStatistics() != null && ticker.getOverallStatistics().getBuyPricePair() != null ? ticker.getOverallStatistics().getBuyPricePair().getAmount() : null; BigDecimal sell = ticker.getOverallStatistics() != null && ticker.getOverallStatistics().getSellPricePair() != null ? ticker.getOverallStatistics().getSellPricePair().getAmount() : null; BigDecimal volume = ticker.getDailyStatistics() != null && ticker.getDailyStatistics().getVolumePair() != null ? ticker.getDailyStatistics().getVolumePair().getAmount() : null; Date date = ticker.getOverallStatistics() != null ? ticker.getOverallStatistics().getTimestamp() : new Date(); return new Ticker.Builder().currencyPair(currencyPair).last(last).high(high).low(low).bid(buy).ask(sell).volume(volume).timestamp(date).build(); }
15. PoloniexAdapters#adaptPoloniexTicker()
Project: XChange
File: PoloniexAdapters.java
File: PoloniexAdapters.java
public static Ticker adaptPoloniexTicker(PoloniexTicker poloniexTicker, CurrencyPair currencyPair) { PoloniexMarketData marketData = poloniexTicker.getPoloniexMarketData(); BigDecimal last = marketData.getLast(); BigDecimal bid = marketData.getHighestBid(); BigDecimal ask = marketData.getLowestAsk(); BigDecimal high = marketData.getHigh24hr(); BigDecimal low = marketData.getLow24hr(); BigDecimal volume = marketData.getQuoteVolume(); return new Ticker.Builder().currencyPair(currencyPair).last(last).bid(bid).ask(ask).high(high).low(low).volume(volume).build(); }
16. MercadoBitcoinAdapters#adaptTicker()
Project: XChange
File: MercadoBitcoinAdapters.java
File: MercadoBitcoinAdapters.java
/** * Adapts a MercadoBitcoinTicker to a Ticker Object * * @param mercadoBitcoinTicker The exchange specific ticker * @param currencyPair (e.g. BTC/USD) * @return The ticker */ public static Ticker adaptTicker(MercadoBitcoinTicker mercadoBitcoinTicker, CurrencyPair currencyPair) { BigDecimal last = mercadoBitcoinTicker.getTicker().getLast(); BigDecimal bid = mercadoBitcoinTicker.getTicker().getBuy(); BigDecimal ask = mercadoBitcoinTicker.getTicker().getSell(); BigDecimal high = mercadoBitcoinTicker.getTicker().getHigh(); BigDecimal low = mercadoBitcoinTicker.getTicker().getLow(); BigDecimal volume = mercadoBitcoinTicker.getTicker().getVol(); Date timestamp = new Date(mercadoBitcoinTicker.getTicker().getDate() * 1000L); return new Ticker.Builder().currencyPair(currencyPair).last(last).bid(bid).ask(ask).high(high).low(low).volume(volume).timestamp(timestamp).build(); }
17. ItBitAdapters#adaptTicker()
Project: XChange
File: ItBitAdapters.java
File: ItBitAdapters.java
public static Ticker adaptTicker(CurrencyPair currencyPair, ItBitTicker itBitTicker) { BigDecimal bid = itBitTicker.getBid(); BigDecimal ask = itBitTicker.getAsk(); BigDecimal high = itBitTicker.getHighToday(); BigDecimal low = itBitTicker.getLowToday(); BigDecimal last = itBitTicker.getLastPrice(); BigDecimal volume = itBitTicker.getVolume24h(); Date timestamp = itBitTicker.getTimestamp() != null ? parseDate(itBitTicker.getTimestamp()) : null; return new Ticker.Builder().currencyPair(currencyPair).last(last).bid(bid).ask(ask).high(high).low(low).volume(volume).timestamp(timestamp).build(); }
18. HitbtcAdapters#adaptTicker()
Project: XChange
File: HitbtcAdapters.java
File: HitbtcAdapters.java
/** * Adapts a HitbtcTicker to a Ticker Object * * @param hitbtcTicker The exchange specific ticker * @param currencyPair (e.g. BTC/USD) * @return The ticker */ public static Ticker adaptTicker(HitbtcTicker hitbtcTicker, CurrencyPair currencyPair) { BigDecimal bid = hitbtcTicker.getBid(); BigDecimal ask = hitbtcTicker.getAsk(); BigDecimal high = hitbtcTicker.getHigh(); BigDecimal low = hitbtcTicker.getLow(); BigDecimal last = hitbtcTicker.getLast(); BigDecimal volume = hitbtcTicker.getVolume(); Date timestamp = new Date(hitbtcTicker.getTimestamp()); return new Ticker.Builder().currencyPair(currencyPair).last(last).bid(bid).ask(ask).high(high).low(low).volume(volume).timestamp(timestamp).build(); }
19. CryptsyAdapters#adaptPublicTicker()
Project: XChange
File: CryptsyAdapters.java
File: CryptsyAdapters.java
/** * Adapts CryptsyPublicMarketData DTO to XChange standard Ticker DTO Note: Cryptsy does not natively have a Ticker method, so getCryptsyMarketData * function will have to be called to get summary data * * @param publicMarketData Raw returned data from Cryptsy, CryptsyGetMarketsReturn DTO * @return Standard XChange Ticker DTO */ public static Ticker adaptPublicTicker(CryptsyPublicMarketData publicMarketData) { List<CryptsyPublicTrade> recentTrades = publicMarketData.getRecentTrades(); BigDecimal last = (recentTrades != null && recentTrades.size() > 0) ? recentTrades.get(0).getPrice() : null; List<CryptsyPublicOrder> bids = publicMarketData.getBuyOrders(); BigDecimal bid = (bids != null && bids.size() > 0) ? bids.get(0).getPrice() : null; List<CryptsyPublicOrder> asks = publicMarketData.getSellOrders(); BigDecimal ask = (asks != null && asks.size() > 0) ? asks.get(0).getPrice() : null; BigDecimal high = null; BigDecimal low = null; BigDecimal volume = publicMarketData.getVolume(); Date timestamp = publicMarketData.getLastTradeTime(); return new Ticker.Builder().currencyPair(adaptCurrencyPair(publicMarketData)).last(last).bid(bid).ask(ask).high(high).low(low).volume(volume).timestamp(timestamp).build(); }
20. CryptsyAdapters#adaptTicker()
Project: XChange
File: CryptsyAdapters.java
File: CryptsyAdapters.java
/** * Adapts CryptsyGetMarketsReturn DTO to XChange standard Ticker DTO Note: Cryptsy does not natively have a Ticker method, so getMarkets function * will have to be called to get summary data * * @param marketsReturnData Raw returned data from Cryptsy, CryptsyGetMarketsReturn DTO * @param currencyPair The market for which this CryptsyGetMarketsReturn belongs to (Usually not given in Cryptsy response) * @return Standard XChange Ticker DTO */ public static Ticker adaptTicker(CryptsyGetMarketsReturn marketsReturnData, CurrencyPair currencyPair) { List<CryptsyMarketData> marketData = marketsReturnData.getReturnValue(); String label = currencyPair.toString().replace("_", "/"); CryptsyMarketData targetMarket = null; for (CryptsyMarketData currMarket : marketData) { if (currMarket.getLabel().equalsIgnoreCase(label)) { targetMarket = currMarket; break; } } BigDecimal last = targetMarket.getLast(); BigDecimal bid = null; BigDecimal ask = null; BigDecimal high = targetMarket.getHigh(); BigDecimal low = targetMarket.getLow(); BigDecimal volume = targetMarket.get24hVolume(); Date timestamp = targetMarket.getCreatedTime(); return new Ticker.Builder().currencyPair(currencyPair).last(last).bid(bid).ask(ask).high(high).low(low).volume(volume).timestamp(timestamp).build(); }
21. CryptonitAdapters#adaptTicker()
Project: XChange
File: CryptonitAdapters.java
File: CryptonitAdapters.java
/** * Adapts a cryptonitTicker to a Ticker Object * * @param cryptonitTicker * @return */ public static Ticker adaptTicker(CryptonitTicker cryptonitTicker, CurrencyPair currencyPair) { CryptonitRate rate = cryptonitTicker.getRate(); BigDecimal last = rate.getLast(); BigDecimal high = rate.getHigh(); BigDecimal low = rate.getLow(); BigDecimal bid = rate.getBid(); BigDecimal ask = rate.getAsk(); BigDecimal volume = cryptonitTicker.getVolume().getVolume(currencyPair.base.getCurrencyCode()); return new Ticker.Builder().currencyPair(currencyPair).last(last).high(high).low(low).bid(bid).ask(ask).volume(volume).build(); }
22. ValueMetaTest#testCompareBigNumberNormalStorageData()
Project: pentaho-kettle
File: ValueMetaTest.java
File: ValueMetaTest.java
public void testCompareBigNumberNormalStorageData() throws Exception { BigDecimal number1 = new BigDecimal("987908798769876.23943409"); BigDecimal number2 = new BigDecimal("999908798769876.23943409"); BigDecimal number3 = new BigDecimal("955908798769876.23943409"); BigDecimal number4 = new BigDecimal("987908798769876.23943409"); BigDecimal number5 = null; BigDecimal number6 = null; ValueMetaInterface one = new ValueMeta("one", ValueMetaInterface.TYPE_BIGNUMBER); ValueMetaInterface two = new ValueMeta("two", ValueMetaInterface.TYPE_BIGNUMBER); assertTrue(one.compare(number1, number2) < 0); assertTrue(one.compare(number1, number3) > 0); assertTrue(one.compare(number1, number4) == 0); assertTrue(one.compare(number1, number5) != 0); assertTrue(one.compare(number5, number6) == 0); assertTrue(one.compare(number1, two, number2) < 0); assertTrue(one.compare(number1, two, number3) > 0); assertTrue(one.compare(number1, two, number4) == 0); assertTrue(one.compare(number1, two, number5) != 0); assertTrue(one.compare(number5, two, number6) == 0); }
23. CoinmateAdapters#adaptTicker()
Project: XChange
File: CoinmateAdapters.java
File: CoinmateAdapters.java
/** * Adapts a CoinmateTicker to a Ticker Object * * @param coinmateTicker The exchange specific ticker * @param currencyPair (e.g. BTC/USD) * @return The ticker */ public static Ticker adaptTicker(CoinmateTicker coinmateTicker, CurrencyPair currencyPair) { BigDecimal last = coinmateTicker.getData().getLast(); BigDecimal bid = coinmateTicker.getData().getBid(); BigDecimal ask = coinmateTicker.getData().getAsk(); BigDecimal high = coinmateTicker.getData().getHigh(); BigDecimal low = coinmateTicker.getData().getLow(); BigDecimal volume = coinmateTicker.getData().getAmount(); return new Ticker.Builder().currencyPair(currencyPair).last(last).bid(bid).ask(ask).high(high).low(low).volume(volume).build(); }
24. CoinbaseExAdapters#adaptTicker()
Project: XChange
File: CoinbaseExAdapters.java
File: CoinbaseExAdapters.java
public static Ticker adaptTicker(CoinbaseExProductTicker ticker, CoinbaseExProductStats stats, CoinbaseExProductBook book, CurrencyPair currencyPair) { BigDecimal last = ticker != null ? ticker.getPrice() : null; BigDecimal high = stats != null ? stats.getHigh() : null; BigDecimal low = stats != null ? stats.getLow() : null; BigDecimal buy = book != null ? book.getBestBid().getPrice() : null; BigDecimal sell = book != null ? book.getBestAsk().getPrice() : null; BigDecimal volume = stats != null ? stats.getVolume() : null; Date date = ticker != null ? ticker.getTime() : new Date(); return new Ticker.Builder().currencyPair(currencyPair).last(last).high(high).low(low).bid(buy).ask(sell).volume(volume).timestamp(date).build(); }
25. CleverCoinAdapters#adaptTicker()
Project: XChange
File: CleverCoinAdapters.java
File: CleverCoinAdapters.java
/** * Adapts a CleverCoinTicker to a Ticker Object * * @param cleverCoinTicker The exchange specific ticker * @param currencyPair (e.g. BTC/USD) * @return The ticker */ public static Ticker adaptTicker(CleverCoinTicker cleverCoinTicker, CurrencyPair currencyPair) { BigDecimal last = cleverCoinTicker.getLast(); BigDecimal bid = cleverCoinTicker.getBid(); BigDecimal ask = cleverCoinTicker.getAsk(); BigDecimal high = cleverCoinTicker.getHigh(); BigDecimal low = cleverCoinTicker.getLow(); BigDecimal volume = cleverCoinTicker.getVolume(); Date timestamp = new Date(cleverCoinTicker.getTimestamp() * 1000L); return new Ticker.Builder().currencyPair(currencyPair).last(last).bid(bid).ask(ask).high(high).low(low).volume(volume).timestamp(timestamp).build(); }
26. CexIOAdapters#adaptTicker()
Project: XChange
File: CexIOAdapters.java
File: CexIOAdapters.java
/** * Adapts a CexIOTicker to a Ticker Object * * @param ticker The exchange specific ticker * @param currencyPair The currency pair (e.g. BTC/USD) * @return The ticker */ public static Ticker adaptTicker(CexIOTicker ticker, CurrencyPair currencyPair) { BigDecimal last = ticker.getLast(); BigDecimal bid = ticker.getBid(); BigDecimal ask = ticker.getAsk(); BigDecimal high = ticker.getHigh(); BigDecimal low = ticker.getLow(); BigDecimal volume = ticker.getVolume(); Date timestamp = new Date(ticker.getTimestamp() * 1000L); return new Ticker.Builder().currencyPair(currencyPair).last(last).bid(bid).ask(ask).high(high).low(low).volume(volume).timestamp(timestamp).build(); }
27. BTCCentralAdapters#adaptTicker()
Project: XChange
File: BTCCentralAdapters.java
File: BTCCentralAdapters.java
/** * Adapts a BTCCentralTicker to a Ticker Object * * @param btcCentralTicker The exchange specific ticker * @param currencyPair (e.g. BTC/USD) * @return The ticker */ public static Ticker adaptTicker(BTCCentralTicker btcCentralTicker, CurrencyPair currencyPair) { BigDecimal bid = btcCentralTicker.getBid(); BigDecimal ask = btcCentralTicker.getAsk(); BigDecimal high = btcCentralTicker.getHigh(); BigDecimal low = btcCentralTicker.getLow(); BigDecimal last = btcCentralTicker.getPrice(); BigDecimal volume = btcCentralTicker.getVolume(); Date timestamp = new Date(btcCentralTicker.getAt() * 1000L); return new Ticker.Builder().currencyPair(currencyPair).bid(bid).ask(ask).high(high).low(low).last(last).volume(volume).timestamp(timestamp).build(); }
28. BittrexAdapters#adaptTicker()
Project: XChange
File: BittrexAdapters.java
File: BittrexAdapters.java
public static Ticker adaptTicker(BittrexTicker bittrexTicker, CurrencyPair currencyPair) { BigDecimal last = bittrexTicker.getLast(); BigDecimal bid = bittrexTicker.getBid(); BigDecimal ask = bittrexTicker.getAsk(); BigDecimal high = bittrexTicker.getHigh(); BigDecimal low = bittrexTicker.getLow(); BigDecimal volume = bittrexTicker.getVolume(); Date timestamp = BittrexUtils.toDate(bittrexTicker.getTimeStamp()); return new Ticker.Builder().currencyPair(currencyPair).last(last).bid(bid).ask(ask).high(high).low(low).volume(volume).timestamp(timestamp).build(); }
29. BitKonanAdapters#adaptTicker()
Project: XChange
File: BitKonanAdapters.java
File: BitKonanAdapters.java
/** * Adapts a HitbtcTicker to a Ticker Object * * @param bitKonanTicker The exchange specific ticker * @param currencyPair (e.g. BTC/USD) * @return The ticker */ public static Ticker adaptTicker(BitKonanTicker bitKonanTicker, CurrencyPair currencyPair) { BigDecimal bid = bitKonanTicker.getBid(); BigDecimal ask = bitKonanTicker.getAsk(); BigDecimal high = bitKonanTicker.getHigh(); BigDecimal low = bitKonanTicker.getLow(); BigDecimal last = bitKonanTicker.getLast(); BigDecimal volume = bitKonanTicker.getVolume(); return new Ticker.Builder().currencyPair(currencyPair).last(last).bid(bid).ask(ask).high(high).low(low).volume(volume).build(); }
30. BitfinexAdapters#adaptTicker()
Project: XChange
File: BitfinexAdapters.java
File: BitfinexAdapters.java
public static Ticker adaptTicker(BitfinexTicker bitfinexTicker, CurrencyPair currencyPair) { BigDecimal last = bitfinexTicker.getLast_price(); BigDecimal bid = bitfinexTicker.getBid(); BigDecimal ask = bitfinexTicker.getAsk(); BigDecimal high = bitfinexTicker.getHigh(); BigDecimal low = bitfinexTicker.getLow(); BigDecimal volume = bitfinexTicker.getVolume(); Date timestamp = DateUtils.fromMillisUtc((long) (bitfinexTicker.getTimestamp() * 1000L)); return new Ticker.Builder().currencyPair(currencyPair).last(last).bid(bid).ask(ask).high(high).low(low).volume(volume).timestamp(timestamp).build(); }
31. ANXAdapters#adaptTicker()
Project: XChange
File: ANXAdapters.java
File: ANXAdapters.java
public static Ticker adaptTicker(ANXTicker anxTicker) { BigDecimal volume = anxTicker.getVol().getValue(); BigDecimal last = anxTicker.getLast().getValue(); BigDecimal bid = anxTicker.getBuy().getValue(); BigDecimal ask = anxTicker.getSell().getValue(); BigDecimal high = anxTicker.getHigh().getValue(); BigDecimal low = anxTicker.getLow().getValue(); Date timestamp = new Date(anxTicker.getNow() / 1000); CurrencyPair currencyPair = adaptCurrencyPair(anxTicker.getVol().getCurrency(), anxTicker.getAvg().getCurrency()); return new Ticker.Builder().currencyPair(currencyPair).last(last).bid(bid).ask(ask).high(high).low(low).volume(volume).timestamp(timestamp).build(); }
32. TestDefaultInvoiceUserApi#testOriginalAmountCharged()
Project: killbill
File: TestDefaultInvoiceUserApi.java
File: TestDefaultInvoiceUserApi.java
@Test(groups = "slow") public void testOriginalAmountCharged() throws Exception { final Invoice initialInvoice = invoiceUserApi.getInvoice(invoiceId, callContext); final BigDecimal originalAmountCharged = initialInvoice.getOriginalChargedAmount(); final BigDecimal amountCharged = initialInvoice.getChargedAmount(); Assert.assertEquals(originalAmountCharged.compareTo(amountCharged), 0); ((ClockMock) clock).addDays(1); // Sleep at least one sec to make sure created_date for the external charge is different than the created date for the invoice itself CallContext newCallContextLater = new DefaultCallContext(callContext.getTenantId(), callContext.getUserName(), callContext.getCallOrigin(), callContext.getUserType(), callContext.getUserToken(), clock); // Post an external charge final BigDecimal externalChargeAmount = BigDecimal.TEN; final InvoiceItem externalCharge = new ExternalChargeInvoiceItem(invoiceId, accountId, null, UUID.randomUUID().toString(), clock.getUTCToday(), externalChargeAmount, accountCurrency); final InvoiceItem externalChargeInvoiceItem = invoiceUserApi.insertExternalCharges(accountId, clock.getUTCToday(), ImmutableList.<InvoiceItem>of(externalCharge), newCallContextLater).get(0); final Invoice newInvoice = invoiceUserApi.getInvoice(invoiceId, callContext); final BigDecimal newOriginalAmountCharged = newInvoice.getOriginalChargedAmount(); final BigDecimal newAmountCharged = newInvoice.getChargedAmount(); final BigDecimal expectedChargedAmount = newInvoice.getOriginalChargedAmount().add(externalChargeInvoiceItem.getAmount()); Assert.assertEquals(originalAmountCharged.compareTo(newOriginalAmountCharged), 0); Assert.assertEquals(newAmountCharged.compareTo(expectedChargedAmount), 0); }
33. BigDecimalTest#test_movePointLeftI()
Project: j2objc
File: BigDecimalTest.java
File: BigDecimalTest.java
/** * @tests java.math.BigDecimal#movePointLeft(int) */ public void test_movePointLeftI() { BigDecimal movePtLeft = new BigDecimal("123456265.34"); BigDecimal alreadyMoved = movePtLeft.movePointLeft(5); assertTrue("move point left 5 failed", alreadyMoved.scale() == 7 && alreadyMoved.toString().equals("1234.5626534")); movePtLeft = new BigDecimal(value2.negate(), 0); alreadyMoved = movePtLeft.movePointLeft(12); assertTrue("move point left 12 failed", alreadyMoved.scale() == 12 && alreadyMoved.toString().equals("-0.012334560000")); movePtLeft = new BigDecimal(123E18); alreadyMoved = movePtLeft.movePointLeft(2); assertTrue("move point left 2 failed", alreadyMoved.scale() == movePtLeft.scale() + 2 && alreadyMoved.doubleValue() == 1.23E18); movePtLeft = new BigDecimal(1.123E-12); alreadyMoved = movePtLeft.movePointLeft(3); assertTrue("move point left 3 failed", alreadyMoved.scale() == movePtLeft.scale() + 3 && alreadyMoved.doubleValue() == 1.123E-15); movePtLeft = new BigDecimal(value, 2); alreadyMoved = movePtLeft.movePointLeft(-2); assertTrue("move point left -2 failed", alreadyMoved.scale() == movePtLeft.scale() - 2 && alreadyMoved.toString().equals("12345908")); }
34. BigDecimalTest#test_maxLjava_math_BigDecimal()
Project: j2objc
File: BigDecimalTest.java
File: BigDecimalTest.java
/** * @tests java.math.BigDecimal#max(java.math.BigDecimal) */ public void test_maxLjava_math_BigDecimal() { BigDecimal max1 = new BigDecimal(value2, 1); BigDecimal max2 = new BigDecimal(value2, 4); assertTrue("1233456000.0 is not greater than 1233456", max1.max(max2).equals(max1)); max1 = new BigDecimal(-1.224D); max2 = new BigDecimal(-1.2245D); assertTrue("-1.224 is not greater than -1.2245", max1.max(max2).equals(max1)); max1 = new BigDecimal(123E18); max2 = new BigDecimal(123E19); assertTrue("123E19 is the not the max", max1.max(max2).equals(max2)); }
35. BigDecimalTest#test_floatValue()
Project: j2objc
File: BigDecimalTest.java
File: BigDecimalTest.java
/** * @tests java.math.BigDecimal#floatValue() */ public void test_floatValue() { BigDecimal fl1 = new BigDecimal("234563782344567"); assertTrue("the float representation of bigDecimal 234563782344567", fl1.floatValue() == 234563782344567f); BigDecimal fl2 = new BigDecimal(2.345E37); assertTrue("the float representation of bigDecimal 2.345E37", fl2.floatValue() == 2.345E37F); fl2 = new BigDecimal(-1.00E-44); assertTrue("the float representation of bigDecimal -1.00E-44", fl2.floatValue() == -1.00E-44F); fl2 = new BigDecimal(-3E12); assertTrue("the float representation of bigDecimal -3E12", fl2.floatValue() == -3E12F); fl2 = new BigDecimal(Double.MAX_VALUE); assertTrue("A number can't be represented by float should return infinity", fl2.floatValue() == Float.POSITIVE_INFINITY); fl2 = new BigDecimal(-Double.MAX_VALUE); assertTrue("A number can't be represented by float should return infinity", fl2.floatValue() == Float.NEGATIVE_INFINITY); }
36. ChargeData#toSavingsAccountChargeData()
Project: incubator-fineract
File: ChargeData.java
File: ChargeData.java
public SavingsAccountChargeData toSavingsAccountChargeData() { final Long savingsChargeId = null; final Long savingsAccountId = null; final BigDecimal amountPaid = BigDecimal.ZERO; final BigDecimal amountWaived = BigDecimal.ZERO; final BigDecimal amountWrittenOff = BigDecimal.ZERO; final BigDecimal amountOutstanding = BigDecimal.ZERO; final BigDecimal percentage = BigDecimal.ZERO; final BigDecimal amountPercentageAppliedTo = BigDecimal.ZERO; final Collection<ChargeData> chargeOptions = null; final LocalDate dueAsOfDate = null; final Boolean isActive = null; final LocalDate inactivationDate = null; return SavingsAccountChargeData.instance(savingsChargeId, this.id, savingsAccountId, this.name, this.currency, this.amount, amountPaid, amountWaived, amountWrittenOff, amountOutstanding, this.chargeTimeType, dueAsOfDate, this.chargeCalculationType, percentage, amountPercentageAppliedTo, chargeOptions, this.penalty, this.feeOnMonthDay, this.feeInterval, isActive, inactivationDate); }
37. LoanRescheduleModel#toData()
Project: incubator-fineract
File: LoanRescheduleModel.java
File: LoanRescheduleModel.java
public LoanScheduleData toData() { final int decimalPlaces = this.totalPrincipalDisbursed.getCurrencyDigitsAfterDecimal(); final Integer inMultiplesOf = this.totalPrincipalDisbursed.getCurrencyInMultiplesOf(); final CurrencyData currency = this.applicationCurrency.toData(decimalPlaces, inMultiplesOf); final Collection<LoanSchedulePeriodData> periodsData = new ArrayList<>(); for (final LoanRescheduleModalPeriod modelPeriod : this.periods) { periodsData.add(modelPeriod.toData()); } final BigDecimal totalWaived = null; final BigDecimal totalWrittenOff = null; final BigDecimal totalRepayment = null; final BigDecimal totalPaidInAdvance = null; final BigDecimal totalPaidLate = null; return new LoanScheduleData(currency, periodsData, this.loanTermInDays, this.totalPrincipalDisbursed.getAmount(), this.totalPrincipalExpected, this.totalPrincipalPaid, this.totalInterestCharged, this.totalFeeChargesCharged, this.totalPenaltyChargesCharged, totalWaived, totalWrittenOff, this.totalRepaymentExpected, totalRepayment, totalPaidInAdvance, totalPaidLate, this.totalOutstanding); }
38. LoanScheduleModel#toData()
Project: incubator-fineract
File: LoanScheduleModel.java
File: LoanScheduleModel.java
public LoanScheduleData toData() { final int decimalPlaces = this.totalPrincipalDisbursed.getCurrencyDigitsAfterDecimal(); final Integer inMultiplesOf = this.totalPrincipalDisbursed.getCurrencyInMultiplesOf(); final CurrencyData currency = this.applicationCurrency.toData(decimalPlaces, inMultiplesOf); final Collection<LoanSchedulePeriodData> periodsData = new ArrayList<>(); for (final LoanScheduleModelPeriod modelPeriod : this.periods) { periodsData.add(modelPeriod.toData()); } final BigDecimal totalWaived = null; final BigDecimal totalWrittenOff = null; final BigDecimal totalRepayment = null; final BigDecimal totalPaidInAdvance = null; final BigDecimal totalPaidLate = null; return new LoanScheduleData(currency, periodsData, this.loanTermInDays, this.totalPrincipalDisbursed.getAmount(), this.totalPrincipalExpected, this.totalPrincipalPaid, this.totalInterestCharged, this.totalFeeChargesCharged, this.totalPenaltyChargesCharged, totalWaived, totalWrittenOff, this.totalRepaymentExpected, totalRepayment, totalPaidInAdvance, totalPaidLate, this.totalOutstanding); }
39. LoanTransaction#accrueInterest()
Project: incubator-fineract
File: LoanTransaction.java
File: LoanTransaction.java
public static LoanTransaction accrueInterest(final Office office, final Loan loan, final Money amount, final LocalDate interestAppliedDate, final LocalDateTime createdDate, final AppUser appUser) { BigDecimal principalPortion = null; BigDecimal feesPortion = null; BigDecimal penaltiesPortion = null; BigDecimal interestPortion = amount.getAmount(); BigDecimal overPaymentPortion = null; boolean reversed = false; PaymentDetail paymentDetail = null; String externalId = null; return new LoanTransaction(loan, office, LoanTransactionType.ACCRUAL.getValue(), interestAppliedDate.toDate(), interestPortion, principalPortion, interestPortion, feesPortion, penaltiesPortion, overPaymentPortion, reversed, paymentDetail, externalId, createdDate, appUser); }
40. ClientChargeData#template()
Project: incubator-fineract
File: ClientChargeData.java
File: ClientChargeData.java
public static ClientChargeData template(final Collection<ChargeData> chargeOptions) { final Long id = null; final Long clientId = null; final Long chargeId = null; final String name = null; final EnumOptionData chargeTimeType = null; final LocalDate dueDate = null; final EnumOptionData chargeCalculationType = null; final CurrencyData currency = null; final BigDecimal amount = null; final BigDecimal amountPaid = null; final BigDecimal amountWaived = null; final BigDecimal amountWrittenOff = null; final BigDecimal amountOutstanding = null; final Boolean penalty = false; final Boolean isPaid = null; final Boolean isActive = null; final Boolean isWaived = null; final LocalDate inactivationDate = null; final Collection<ClientTransactionData> clientTransactionDatas = null; return new ClientChargeData(id, clientId, chargeId, name, chargeTimeType, dueDate, chargeCalculationType, currency, amount, amountPaid, amountWaived, amountWrittenOff, amountOutstanding, penalty, isPaid, isWaived, isActive, inactivationDate, chargeOptions, clientTransactionDatas); }
41. BigDecimalTest#test_scale()
Project: j2objc
File: BigDecimalTest.java
File: BigDecimalTest.java
/** * @tests java.math.BigDecimal#scale() */ public void test_scale() { BigDecimal scale1 = new BigDecimal(value2, 8); assertTrue("the scale of the number 123.34560000 is wrong", scale1.scale() == 8); BigDecimal scale2 = new BigDecimal("29389."); assertTrue("the scale of the number 29389. is wrong", scale2.scale() == 0); BigDecimal scale3 = new BigDecimal(3.374E13); assertTrue("the scale of the number 3.374E13 is wrong", scale3.scale() == 0); BigDecimal scale4 = new BigDecimal("-3.45E-203"); // note the scale is calculated as 15 digits of 345000.... + exponent - // 1. -1 for the 3 assertTrue("the scale of the number -3.45E-203 is wrong: " + scale4.scale(), scale4.scale() == 205); scale4 = new BigDecimal("-345.4E-200"); assertTrue("the scale of the number -345.4E-200 is wrong", scale4.scale() == 201); }
42. BigDecimalTest#test_movePointRightI()
Project: j2objc
File: BigDecimalTest.java
File: BigDecimalTest.java
/** * @tests java.math.BigDecimal#movePointRight(int) */ public void test_movePointRightI() { BigDecimal movePtRight = new BigDecimal("-1.58796521458"); BigDecimal alreadyMoved = movePtRight.movePointRight(8); assertTrue("move point right 8 failed", alreadyMoved.scale() == 3 && alreadyMoved.toString().equals("-158796521.458")); movePtRight = new BigDecimal(value, 2); alreadyMoved = movePtRight.movePointRight(4); assertTrue("move point right 4 failed", alreadyMoved.scale() == 0 && alreadyMoved.toString().equals("1234590800")); movePtRight = new BigDecimal(134E12); alreadyMoved = movePtRight.movePointRight(2); assertTrue("move point right 2 failed", alreadyMoved.scale() == 0 && alreadyMoved.toString().equals("13400000000000000")); movePtRight = new BigDecimal(-3.4E-10); alreadyMoved = movePtRight.movePointRight(5); assertTrue("move point right 5 failed", alreadyMoved.scale() == movePtRight.scale() - 5 && alreadyMoved.doubleValue() == -0.000034); alreadyMoved = alreadyMoved.movePointRight(-5); assertTrue("move point right -5 failed", alreadyMoved.equals(movePtRight)); }
43. BigDecimalTest#test_divideLjava_math_BigDecimalII()
Project: j2objc
File: BigDecimalTest.java
File: BigDecimalTest.java
/** * @tests java.math.BigDecimal#divide(java.math.BigDecimal, int, int) */ public void test_divideLjava_math_BigDecimalII() { BigDecimal divd1 = new BigDecimal(value2, 4); BigDecimal divd2 = new BigDecimal("0.0023"); BigDecimal divd3 = divd1.divide(divd2, 3, BigDecimal.ROUND_HALF_UP); assertTrue("1233456/0.0023 is not correct", divd3.toString().equals("536285217.391") && divd3.scale() == 3); divd2 = new BigDecimal(1345.5E-02D); divd3 = divd1.divide(divd2, 0, BigDecimal.ROUND_DOWN); assertTrue("1233456/13.455 is not correct or does not have the correct scale", divd3.toString().equals("91672") && divd3.scale() == 0); divd2 = new BigDecimal(0000D); try { divd1.divide(divd2, 4, BigDecimal.ROUND_DOWN); fail("divide by zero is not caught"); } catch (ArithmeticException e) { } }
44. BigDecimalTest#test_divideLjava_math_BigDecimalI()
Project: j2objc
File: BigDecimalTest.java
File: BigDecimalTest.java
/** * @tests java.math.BigDecimal#divide(java.math.BigDecimal, int) */ public void test_divideLjava_math_BigDecimalI() { BigDecimal divd1 = new BigDecimal(value, 2); BigDecimal divd2 = new BigDecimal("2.335"); BigDecimal divd3 = divd1.divide(divd2, BigDecimal.ROUND_UP); assertTrue("123459.08/2.335 is not correct", divd3.toString().equals("52873.27") && divd3.scale() == divd1.scale()); assertTrue("the unscaledValue representation of 123459.08/2.335 is not correct", divd3.unscaledValue().toString().equals("5287327")); divd2 = new BigDecimal(123.4D); divd3 = divd1.divide(divd2, BigDecimal.ROUND_DOWN); assertTrue("123459.08/123.4 is not correct", divd3.toString().equals("1000.47") && divd3.scale() == 2); divd2 = new BigDecimal(000D); try { divd1.divide(divd2, BigDecimal.ROUND_DOWN); fail("divide by zero is not caught"); } catch (ArithmeticException e) { } }
45. VariantQuality#getOverallQuality()
Project: Resteasy
File: VariantQuality.java
File: VariantQuality.java
/** * @return the quality value between zero and one with five decimal places after the point. * @see "3.3 Computing overall quality values" */ public BigDecimal getOverallQuality() { BigDecimal qt = BigDecimal.valueOf(mediaTypeQualityValue.intValue(), 3); BigDecimal qc = BigDecimal.valueOf(characterSetQualityValue.intValue(), 3); BigDecimal qe = BigDecimal.valueOf(encodingQualityValue.intValue(), 3); BigDecimal ql = BigDecimal.valueOf(languageQualityValue.intValue(), 3); assert qt.compareTo(BigDecimal.ZERO) >= 0 && qt.compareTo(BigDecimal.ONE) <= 0; assert qc.compareTo(BigDecimal.ZERO) >= 0 && qc.compareTo(BigDecimal.ONE) <= 0; assert qe.compareTo(BigDecimal.ZERO) >= 0 && qe.compareTo(BigDecimal.ONE) <= 0; assert ql.compareTo(BigDecimal.ZERO) >= 0 && ql.compareTo(BigDecimal.ONE) <= 0; BigDecimal result = qt; result = result.multiply(qc, MathContext.DECIMAL32); result = result.multiply(qe, MathContext.DECIMAL32); result = result.multiply(ql, MathContext.DECIMAL32); assert result.compareTo(BigDecimal.ZERO) >= 0 && result.compareTo(BigDecimal.ONE) <= 0; long round5 = result.scaleByPowerOfTen(5).longValue(); result = BigDecimal.valueOf(round5, 5); assert result.compareTo(BigDecimal.ZERO) >= 0 && result.compareTo(BigDecimal.ONE) <= 0; return result; }
46. OrderElement#calculateBudgetWithMargin()
Project: libreplan
File: OrderElement.java
File: OrderElement.java
/** * Calculates the budget with the margin {@link Order#getBudgetMargin()} for * this orderElement * * @return calculated budget */ private BigDecimal calculateBudgetWithMargin() { BigDecimal margin = this.getOrder().getBudgetMargin() != null ? new BigDecimal(this.getOrder().getBudgetMargin()) : BigDecimal.ZERO; BigDecimal hundred = new BigDecimal(100); BigDecimal budget = getBudget(); BigDecimal marginBudget = budget.multiply(margin).divide(hundred, 2, BigDecimal.ROUND_HALF_EVEN); return budget.add(marginBudget); }
47. OrderElement#calculateWorkHoursWithMargin()
Project: libreplan
File: OrderElement.java
File: OrderElement.java
/** * Calculates the work hours with the margin {@link Order#getHoursMargin()} * for this orderElement * * @return calculated work hours */ private EffortDuration calculateWorkHoursWithMargin() { BigDecimal margin = this.getOrder().getHoursMargin() != null ? new BigDecimal(this.getOrder().getHoursMargin()).setScale(2) : BigDecimal.ZERO; BigDecimal hundred = new BigDecimal(100); BigDecimal estimatedHours = new BigDecimal(getWorkHours()).setScale(2); BigDecimal marginHours = estimatedHours.multiply(margin).divide(hundred, 2, BigDecimal.ROUND_HALF_EVEN); BigDecimal result = estimatedHours.add(marginHours); return EffortDuration.fromHoursAsBigDecimal(result); }
48. SolarEventCalculator#getSunTrueLongitude()
Project: sunrisesunsetlib-java
File: SolarEventCalculator.java
File: SolarEventCalculator.java
/** * Computes the true longitude of the sun, L in the algorithm, at the given location, adjusted to fit in * the range [0-360]. * * @param meanAnomaly * the suns mean anomaly. * @return the suns true longitude, in <code>BigDecimal</code> form. */ private BigDecimal getSunTrueLongitude(BigDecimal meanAnomaly) { BigDecimal sinMeanAnomaly = new BigDecimal(Math.sin(convertDegreesToRadians(meanAnomaly).doubleValue())); BigDecimal sinDoubleMeanAnomaly = new BigDecimal(Math.sin(multiplyBy(convertDegreesToRadians(meanAnomaly), BigDecimal.valueOf(2)).doubleValue())); BigDecimal firstPart = meanAnomaly.add(multiplyBy(sinMeanAnomaly, new BigDecimal("1.916"))); BigDecimal secondPart = multiplyBy(sinDoubleMeanAnomaly, new BigDecimal("0.020")).add(new BigDecimal("282.634")); BigDecimal trueLongitude = firstPart.add(secondPart); if (trueLongitude.doubleValue() > 360) { trueLongitude = trueLongitude.subtract(BigDecimal.valueOf(360)); } return setScale(trueLongitude); }
49. InvoiceDaoHelper#computePositiveRefundAmount()
Project: killbill
File: InvoiceDaoHelper.java
File: InvoiceDaoHelper.java
public BigDecimal computePositiveRefundAmount(final InvoicePaymentModelDao payment, final BigDecimal requestedRefundAmount, final Map<UUID, BigDecimal> invoiceItemIdsWithAmounts) throws InvoiceApiException { final BigDecimal maxRefundAmount = payment.getAmount() == null ? BigDecimal.ZERO : payment.getAmount(); final BigDecimal requestedPositiveAmount = requestedRefundAmount == null ? maxRefundAmount : requestedRefundAmount; // (But that should have been checked in the payment call already) if (requestedPositiveAmount.compareTo(maxRefundAmount) > 0) { throw new InvoiceApiException(ErrorCode.REFUND_AMOUNT_TOO_HIGH, requestedPositiveAmount, maxRefundAmount); } // Verify if the requested amount matches the invoice items to adjust, if specified BigDecimal amountFromItems = BigDecimal.ZERO; for (final BigDecimal itemAmount : invoiceItemIdsWithAmounts.values()) { amountFromItems = amountFromItems.add(itemAmount); } // Sanity check: if some items were specified, then the sum should be equal to specified refund amount, if specified if (amountFromItems.compareTo(BigDecimal.ZERO) != 0 && requestedPositiveAmount.compareTo(amountFromItems) < 0) { throw new InvoiceApiException(ErrorCode.REFUND_AMOUNT_DONT_MATCH_ITEMS_TO_ADJUST, requestedPositiveAmount, amountFromItems); } return requestedPositiveAmount; }
50. InvoiceDaoHelper#computeItemAdjustmentsForTargetInvoiceItem()
Project: killbill
File: InvoiceDaoHelper.java
File: InvoiceDaoHelper.java
private static void computeItemAdjustmentsForTargetInvoiceItem(final InvoiceItemModelDao targetInvoiceItem, final List<InvoiceItemModelDao> adjustedOrRepairedItems, final Map<UUID, BigDecimal> inputAdjInvoiceItem, final Map<UUID, BigDecimal> outputAdjInvoiceItem) throws InvoiceApiException { final BigDecimal originalItemAmount = targetInvoiceItem.getAmount(); final BigDecimal maxAdjLeftAmount = computeItemAdjustmentAmount(originalItemAmount, adjustedOrRepairedItems); final BigDecimal proposedItemAmount = inputAdjInvoiceItem.get(targetInvoiceItem.getId()); if (proposedItemAmount != null && proposedItemAmount.compareTo(maxAdjLeftAmount) > 0) { throw new InvoiceApiException(ErrorCode.INVOICE_ITEM_ADJUSTMENT_AMOUNT_INVALID, proposedItemAmount, maxAdjLeftAmount); } final BigDecimal itemAmountToAdjust = Objects.firstNonNull(proposedItemAmount, maxAdjLeftAmount); if (itemAmountToAdjust.compareTo(BigDecimal.ZERO) > 0) { outputAdjInvoiceItem.put(targetInvoiceItem.getId(), itemAmountToAdjust); } }
51. BuyZoneModel#sell()
Project: bateman
File: BuyZoneModel.java
File: BuyZoneModel.java
@Override public boolean sell(DateTime time, Session session) { if (!session.inMarket(time)) { return false; } BigDecimal open = asset.getTimeSeries().openOnDay(time); DateTime buyDate = session.lastTrade().getOpen(); BigDecimal buyPrice = asset.priceAt(buyDate); BigDecimal current = asset.priceAt(time); BigDecimal difference = current.subtract(buyPrice); // exit if at end of day, if our sell trigger threshold is reached, // or if we hit our stop loss DateTime endOfDay = asset.getTimeSeries().closeOnDay(time); boolean atEndOfDay = time.compareTo(endOfDay) >= 0; boolean thresholdReached = difference.compareTo(sellTrigger) >= 0; boolean stopLossReached = buyPrice.subtract(current).compareTo(stopLoss) >= 0; return atEndOfDay || thresholdReached || stopLossReached; }
52. AddTests#precisionConsistencyTest()
Project: jdk7u-jdk
File: AddTests.java
File: AddTests.java
/** * Verify calling the precision method should not change the * computed result. */ private static int precisionConsistencyTest() { int failures = 0; MathContext mc = new MathContext(1, RoundingMode.DOWN); //value is equivalent to 19990 BigDecimal a = BigDecimal.valueOf(1999, -1); BigDecimal sum1 = a.add(BigDecimal.ONE, mc); a.precision(); BigDecimal sum2 = a.add(BigDecimal.ONE, mc); if (!sum1.equals(sum2)) { failures++; System.out.println("Unequal sums after calling precision!"); System.out.print("Before:\t"); printAddition(a, BigDecimal.ONE, sum1.toString()); System.out.print("After:\t"); printAddition(a, BigDecimal.ONE, sum2.toString()); } return failures; }
53. AddTests#roundAway()
Project: jdk7u-jdk
File: AddTests.java
File: AddTests.java
private static int roundAway(BigDecimal b1, BigDecimal b2) { int failures = 0; b1.precision(); b2.precision(); BigDecimal b1_negate = b1.negate(); BigDecimal b2_negate = b2.negate(); b1_negate.precision(); b2_negate.precision(); failures += roundAway1(b1, b2); failures += roundAway1(b1, b2_negate); failures += roundAway1(b1_negate, b2); failures += roundAway1(b1_negate, b2_negate); return failures; }
54. Longs#toBinaryUsingBigDecimal()
Project: java-algorithms-implementation
File: Longs.java
File: Longs.java
public static final String toBinaryUsingBigDecimal(long numberToConvert) { long longNumber = numberToConvert; if (longNumber < 0) throw new IllegalArgumentException("Method argument cannot be negative. number=" + longNumber); StringBuilder builder = new StringBuilder(); BigDecimal zero = new BigDecimal(0); BigDecimal two = new BigDecimal(2); BigDecimal number = new BigDecimal(longNumber); BigDecimal[] decimals = null; while (number.compareTo(zero) > 0) { decimals = number.divideAndRemainder(two); number = decimals[0]; builder.append(decimals[1]); } return builder.reverse().toString(); }
55. BigDecimalTest#test_unscaledValue()
Project: j2objc
File: BigDecimalTest.java
File: BigDecimalTest.java
/** * @tests java.math.BigDecimal#unscaledValue() */ public void test_unscaledValue() { BigDecimal unsVal = new BigDecimal("-2839485.000"); assertTrue("the unscaledValue of -2839485.000 is wrong", unsVal.unscaledValue().toString().equals("-2839485000")); unsVal = new BigDecimal(123E10); assertTrue("the unscaledValue of 123E10 is wrong", unsVal.unscaledValue().toString().equals("1230000000000")); unsVal = new BigDecimal("-4.56E-13"); assertTrue("the unscaledValue of -4.56E-13 is wrong: " + unsVal.unscaledValue(), unsVal.unscaledValue().toString().equals("-456")); unsVal = new BigDecimal(value, 3); assertTrue("the unscaledValue of 12345.908 is wrong", unsVal.unscaledValue().toString().equals("12345908")); }
56. BigDecimalTest#test_toString()
Project: j2objc
File: BigDecimalTest.java
File: BigDecimalTest.java
/** * @tests java.math.BigDecimal#toString() */ public void test_toString() { BigDecimal toString1 = new BigDecimal("1234.000"); assertTrue("the toString representation of 1234.000 is wrong", toString1.toString().equals("1234.000")); toString1 = new BigDecimal("-123.4E-5"); assertTrue("the toString representation of -123.4E-5 is wrong: " + toString1, toString1.toString().equals("-0.001234")); toString1 = new BigDecimal("-1.455E-20"); assertTrue("the toString representation of -1.455E-20 is wrong", toString1.toString().equals("-1.455E-20")); toString1 = new BigDecimal(value2, 4); assertTrue("the toString representation of 1233456.0000 is wrong", toString1.toString().equals("1233456.0000")); }
57. BigDecimalTest#test_toBigInteger()
Project: j2objc
File: BigDecimalTest.java
File: BigDecimalTest.java
/** * @tests java.math.BigDecimal#toBigInteger() */ public void test_toBigInteger() { BigDecimal sub1 = new BigDecimal("-29830.989"); BigInteger result = sub1.toBigInteger(); assertTrue("the bigInteger equivalent of -29830.989 is wrong", result.toString().equals("-29830")); sub1 = new BigDecimal(-2837E10); result = sub1.toBigInteger(); assertTrue("the bigInteger equivalent of -2837E10 is wrong", result.doubleValue() == -2837E10); sub1 = new BigDecimal(2.349E-10); result = sub1.toBigInteger(); assertTrue("the bigInteger equivalent of 2.349E-10 is wrong", result.equals(BigInteger.ZERO)); sub1 = new BigDecimal(value2, 6); result = sub1.toBigInteger(); assertTrue("the bigInteger equivalent of 12334.560000 is wrong", result.toString().equals("12334")); }
58. BigDecimalTest#test_intValue()
Project: j2objc
File: BigDecimalTest.java
File: BigDecimalTest.java
/** * @tests java.math.BigDecimal#intValue() */ public void test_intValue() { BigDecimal int1 = new BigDecimal(value, 3); assertTrue("the int value of 12345.908 is not 12345", int1.intValue() == 12345); int1 = new BigDecimal("1.99"); assertTrue("the int value of 1.99 is not 1", int1.intValue() == 1); int1 = new BigDecimal("23423419083091823091283933"); // ran JDK and found representation for the above was -249268259 assertTrue("the int value of 23423419083091823091283933 is wrong", int1.intValue() == -249268259); int1 = new BigDecimal(-1235D); assertTrue("the int value of -1235 is not -1235", int1.intValue() == -1235); }
59. BigDecimalTest#test_compareToLjava_math_BigDecimal()
Project: j2objc
File: BigDecimalTest.java
File: BigDecimalTest.java
/** * @tests java.math.BigDecimal#compareTo(java.math.BigDecimal) */ public void test_compareToLjava_math_BigDecimal() { BigDecimal comp1 = new BigDecimal("1.00"); BigDecimal comp2 = new BigDecimal(1.000000D); assertTrue("1.00 and 1.000000 should be equal", comp1.compareTo(comp2) == 0); BigDecimal comp3 = new BigDecimal("1.02"); assertTrue("1.02 should be bigger than 1.00", comp3.compareTo(comp1) == 1); BigDecimal comp4 = new BigDecimal(0.98D); assertTrue("0.98 should be less than 1.00", comp4.compareTo(comp1) == -1); }
60. BigDecimalTest#test_addLjava_math_BigDecimal()
Project: j2objc
File: BigDecimalTest.java
File: BigDecimalTest.java
/** * @tests java.math.BigDecimal#add(java.math.BigDecimal) */ public void test_addLjava_math_BigDecimal() { BigDecimal add1 = new BigDecimal("23.456"); BigDecimal add2 = new BigDecimal("3849.235"); BigDecimal sum = add1.add(add2); assertTrue("the sum of 23.456 + 3849.235 is wrong", sum.unscaledValue().toString().equals("3872691") && sum.scale() == 3); assertTrue("the sum of 23.456 + 3849.235 is not printed correctly", sum.toString().equals("3872.691")); BigDecimal add3 = new BigDecimal(12.34E02D); assertTrue("the sum of 23.456 + 12.34E02 is not printed correctly", (add1.add(add3)).toString().equals("1257.456")); }
61. DecimalTest#testDecimalHash()
Project: ion-java
File: DecimalTest.java
File: DecimalTest.java
//========================================================================= // Test cases /** * Ensure that {@link Decimal#equals} and {@link Decimal#hashCode} * are in sync. */ @Test public void testDecimalHash() { BigDecimal d1 = new BigDecimal("0."); BigDecimal d2 = Decimal.valueOf("0."); assertEquals(d1, d2); assertEquals("hash code", d1.hashCode(), d2.hashCode()); d1 = new BigDecimal("0.00"); d2 = Decimal.valueOf("0.00"); assertEquals(d1, d2); assertEquals("hash code", d1.hashCode(), d2.hashCode()); // Decimal doesn't override equals() so it negative and positive zeros // are equal. We can't change that since we can't make it symmetric. // We must also keep the hash codes the same. d1 = new BigDecimal("0.00"); d2 = Decimal.valueOf("-0.00"); assertEquals(d1, d2); assertEquals("hash code", d1.hashCode(), d2.hashCode()); }
62. LoanProductRelatedDetailTestHelper#createSettingsForIrregularFlatEveryFourMonths()
Project: incubator-fineract
File: LoanProductRelatedDetailTestHelper.java
File: LoanProductRelatedDetailTestHelper.java
public static LoanProductRelatedDetail createSettingsForIrregularFlatEveryFourMonths() { final MonetaryCurrency currency = new MonetaryCurrencyBuilder().withCode("KSH").withDigitsAfterDecimal(0).build(); final BigDecimal defaultPrincipal = BigDecimal.valueOf(Double.valueOf("15000")); // 2% per month, 24% per year final BigDecimal defaultNominalInterestRatePerPeriod = BigDecimal.valueOf(Double.valueOf("2")); final PeriodFrequencyType interestPeriodFrequencyType = PeriodFrequencyType.MONTHS; final BigDecimal defaultAnnualNominalInterestRate = BigDecimal.valueOf(Double.valueOf("24")); final InterestMethod interestMethod = InterestMethod.FLAT; final InterestCalculationPeriodMethod interestCalculationPeriodMethod = InterestCalculationPeriodMethod.SAME_AS_REPAYMENT_PERIOD; final Integer repayEvery = Integer.valueOf(3); final PeriodFrequencyType repaymentFrequencyType = PeriodFrequencyType.MONTHS; final Integer defaultNumberOfRepayments = Integer.valueOf(2); final BigDecimal inArrearsTolerance = BigDecimal.ZERO; final AmortizationMethod amortizationMethod = AmortizationMethod.EQUAL_PRINCIPAL; return createLoanProductRelatedDetail(currency, defaultPrincipal, defaultNominalInterestRatePerPeriod, interestPeriodFrequencyType, defaultAnnualNominalInterestRate, interestMethod, interestCalculationPeriodMethod, repayEvery, repaymentFrequencyType, defaultNumberOfRepayments, amortizationMethod, inArrearsTolerance); }
63. LoanProductRelatedDetailTestHelper#createSettingsForFlatQuarterly()
Project: incubator-fineract
File: LoanProductRelatedDetailTestHelper.java
File: LoanProductRelatedDetailTestHelper.java
public static LoanProductRelatedDetail createSettingsForFlatQuarterly(final AmortizationMethod amortizationMethod) { final MonetaryCurrency currency = new MonetaryCurrencyBuilder().withCode("USD").withDigitsAfterDecimal(2).build(); final BigDecimal defaultPrincipal = BigDecimal.valueOf(Double.valueOf("200000")); // 2% per month, 24% per year final BigDecimal defaultNominalInterestRatePerPeriod = BigDecimal.valueOf(Double.valueOf("2")); final PeriodFrequencyType interestPeriodFrequencyType = PeriodFrequencyType.MONTHS; final BigDecimal defaultAnnualNominalInterestRate = BigDecimal.valueOf(Double.valueOf("24")); final InterestMethod interestMethod = InterestMethod.FLAT; final InterestCalculationPeriodMethod interestCalculationPeriodMethod = InterestCalculationPeriodMethod.SAME_AS_REPAYMENT_PERIOD; final Integer repayEvery = Integer.valueOf(3); final PeriodFrequencyType repaymentFrequencyType = PeriodFrequencyType.MONTHS; final Integer defaultNumberOfRepayments = Integer.valueOf(4); final BigDecimal inArrearsTolerance = BigDecimal.ZERO; return createLoanProductRelatedDetail(currency, defaultPrincipal, defaultNominalInterestRatePerPeriod, interestPeriodFrequencyType, defaultAnnualNominalInterestRate, interestMethod, interestCalculationPeriodMethod, repayEvery, repaymentFrequencyType, defaultNumberOfRepayments, amortizationMethod, inArrearsTolerance); }
64. LoanProductRelatedDetailTestHelper#createSettingsForEqualInstallmentAmortizationQuarterly()
Project: incubator-fineract
File: LoanProductRelatedDetailTestHelper.java
File: LoanProductRelatedDetailTestHelper.java
public static LoanProductRelatedDetail createSettingsForEqualInstallmentAmortizationQuarterly() { final MonetaryCurrency currency = new MonetaryCurrencyBuilder().withCode("USD").withDigitsAfterDecimal(2).build(); final BigDecimal defaultPrincipal = BigDecimal.valueOf(Double.valueOf("200000")); // 2% per month, 24% per year final BigDecimal defaultNominalInterestRatePerPeriod = BigDecimal.valueOf(Double.valueOf("2")); final PeriodFrequencyType interestPeriodFrequencyType = PeriodFrequencyType.MONTHS; final BigDecimal defaultAnnualNominalInterestRate = BigDecimal.valueOf(Double.valueOf("24")); final InterestMethod interestMethod = InterestMethod.DECLINING_BALANCE; final InterestCalculationPeriodMethod interestCalculationPeriodMethod = InterestCalculationPeriodMethod.SAME_AS_REPAYMENT_PERIOD; final Integer repayEvery = Integer.valueOf(3); final PeriodFrequencyType repaymentFrequencyType = PeriodFrequencyType.MONTHS; final Integer defaultNumberOfRepayments = Integer.valueOf(4); final AmortizationMethod amortizationMethod = AmortizationMethod.EQUAL_INSTALLMENTS; final BigDecimal inArrearsTolerance = BigDecimal.ZERO; return createLoanProductRelatedDetail(currency, defaultPrincipal, defaultNominalInterestRatePerPeriod, interestPeriodFrequencyType, defaultAnnualNominalInterestRate, interestMethod, interestCalculationPeriodMethod, repayEvery, repaymentFrequencyType, defaultNumberOfRepayments, amortizationMethod, inArrearsTolerance); }
65. LoanProductRelatedDetailTestHelper#createSettingsForEqualPrincipalAmortizationQuarterly()
Project: incubator-fineract
File: LoanProductRelatedDetailTestHelper.java
File: LoanProductRelatedDetailTestHelper.java
public static LoanProductRelatedDetail createSettingsForEqualPrincipalAmortizationQuarterly() { final MonetaryCurrency currency = new MonetaryCurrencyBuilder().withCode("USD").withDigitsAfterDecimal(2).build(); final BigDecimal defaultPrincipal = BigDecimal.valueOf(Double.valueOf("200000")); // 2% per month, 24% per year final BigDecimal defaultNominalInterestRatePerPeriod = BigDecimal.valueOf(Double.valueOf("2")); final PeriodFrequencyType interestPeriodFrequencyType = PeriodFrequencyType.MONTHS; final BigDecimal defaultAnnualNominalInterestRate = BigDecimal.valueOf(Double.valueOf("24")); final InterestMethod interestMethod = InterestMethod.DECLINING_BALANCE; final InterestCalculationPeriodMethod interestCalculationPeriodMethod = InterestCalculationPeriodMethod.SAME_AS_REPAYMENT_PERIOD; final Integer repayEvery = Integer.valueOf(3); final PeriodFrequencyType repaymentFrequencyType = PeriodFrequencyType.MONTHS; final Integer defaultNumberOfRepayments = Integer.valueOf(4); final AmortizationMethod amortizationMethod = AmortizationMethod.EQUAL_PRINCIPAL; final BigDecimal inArrearsTolerance = BigDecimal.ZERO; return createLoanProductRelatedDetail(currency, defaultPrincipal, defaultNominalInterestRatePerPeriod, interestPeriodFrequencyType, defaultAnnualNominalInterestRate, interestMethod, interestCalculationPeriodMethod, repayEvery, repaymentFrequencyType, defaultNumberOfRepayments, amortizationMethod, inArrearsTolerance); }
66. ShareAccountCharge#calculateOutstanding()
Project: incubator-fineract
File: ShareAccountCharge.java
File: ShareAccountCharge.java
private BigDecimal calculateOutstanding() { BigDecimal amountPaidLocal = BigDecimal.ZERO; if (this.amountPaid != null) { amountPaidLocal = this.amountPaid; } BigDecimal amountWaivedLocal = BigDecimal.ZERO; if (this.amountWaived != null) { amountWaivedLocal = this.amountWaived; } BigDecimal amountWrittenOffLocal = BigDecimal.ZERO; if (this.amountWrittenOff != null) { amountWrittenOffLocal = this.amountWrittenOff; } final BigDecimal totalAccountedFor = amountPaidLocal.add(amountWaivedLocal).add(amountWrittenOffLocal); return this.amount.subtract(totalAccountedFor); }
67. SavingsAccountCharge#calculateOutstanding()
Project: incubator-fineract
File: SavingsAccountCharge.java
File: SavingsAccountCharge.java
private BigDecimal calculateOutstanding() { BigDecimal amountPaidLocal = BigDecimal.ZERO; if (this.amountPaid != null) { amountPaidLocal = this.amountPaid; } BigDecimal amountWaivedLocal = BigDecimal.ZERO; if (this.amountWaived != null) { amountWaivedLocal = this.amountWaived; } BigDecimal amountWrittenOffLocal = BigDecimal.ZERO; if (this.amountWrittenOff != null) { amountWrittenOffLocal = this.amountWrittenOff; } final BigDecimal totalAccountedFor = amountPaidLocal.add(amountWaivedLocal).add(amountWrittenOffLocal); return this.amount.subtract(totalAccountedFor); }
68. LoanApplicationTerms#interestRateFor()
Project: incubator-fineract
File: LoanApplicationTerms.java
File: LoanApplicationTerms.java
public BigDecimal interestRateFor(final PaymentPeriodsInOneYearCalculator calculator, final MathContext mc, final Money outstandingBalance, final LocalDate fromDate, final LocalDate toDate) { long loanTermPeriodsInOneYear = calculator.calculate(PeriodFrequencyType.DAYS).longValue(); int repaymentEvery = Days.daysBetween(fromDate, toDate).getDays(); if (isFallingInRepaymentPeriod(fromDate, toDate)) { loanTermPeriodsInOneYear = calculatePeriodsInOneYear(calculator); repaymentEvery = getPeriodsBetween(fromDate, toDate); } final BigDecimal divisor = BigDecimal.valueOf(Double.valueOf("100.0")); final BigDecimal loanTermPeriodsInYearBigDecimal = BigDecimal.valueOf(loanTermPeriodsInOneYear); final BigDecimal oneDayOfYearInterestRate = this.annualNominalInterestRate.divide(loanTermPeriodsInYearBigDecimal, mc).divide(divisor, mc); BigDecimal interestRate = oneDayOfYearInterestRate.multiply(BigDecimal.valueOf(repaymentEvery), mc); return outstandingBalance.getAmount().multiply(interestRate, mc); }
69. LoanInstallmentCharge#calculateOutstanding()
Project: incubator-fineract
File: LoanInstallmentCharge.java
File: LoanInstallmentCharge.java
private BigDecimal calculateOutstanding() { if (this.amount == null) { return null; } BigDecimal amountPaidLocal = BigDecimal.ZERO; if (this.amountPaid != null) { amountPaidLocal = this.amountPaid; } BigDecimal amountWaivedLocal = BigDecimal.ZERO; if (this.amountWaived != null) { amountWaivedLocal = this.amountWaived; } BigDecimal amountWrittenOffLocal = BigDecimal.ZERO; if (this.amountWrittenOff != null) { amountWrittenOffLocal = this.amountWrittenOff; } final BigDecimal totalAccountedFor = amountPaidLocal.add(amountWaivedLocal).add(amountWrittenOffLocal); return this.amount.subtract(totalAccountedFor); }
70. LoanCharge#calculateOutstanding()
Project: incubator-fineract
File: LoanCharge.java
File: LoanCharge.java
private BigDecimal calculateOutstanding() { if (this.amount == null) { return null; } BigDecimal amountPaidLocal = BigDecimal.ZERO; if (this.amountPaid != null) { amountPaidLocal = this.amountPaid; } BigDecimal amountWaivedLocal = BigDecimal.ZERO; if (this.amountWaived != null) { amountWaivedLocal = this.amountWaived; } BigDecimal amountWrittenOffLocal = BigDecimal.ZERO; if (this.amountWrittenOff != null) { amountWrittenOffLocal = this.amountWrittenOff; } final BigDecimal totalAccountedFor = amountPaidLocal.add(amountWaivedLocal).add(amountWrittenOffLocal); return this.amount.subtract(totalAccountedFor); }
71. ClientCharge#calculateOutstanding()
Project: incubator-fineract
File: ClientCharge.java
File: ClientCharge.java
private BigDecimal calculateOutstanding() { BigDecimal amountPaidLocal = BigDecimal.ZERO; if (this.amountPaid != null) { amountPaidLocal = this.amountPaid; } BigDecimal amountWaivedLocal = BigDecimal.ZERO; if (this.amountWaived != null) { amountWaivedLocal = this.amountWaived; } BigDecimal amountWrittenOffLocal = BigDecimal.ZERO; if (this.amountWrittenOff != null) { amountWrittenOffLocal = this.amountWrittenOff; } final BigDecimal totalAccountedFor = amountPaidLocal.add(amountWaivedLocal).add(amountWrittenOffLocal); return this.amount.subtract(totalAccountedFor); }
72. AddTests#roundAway()
Project: openjdk
File: AddTests.java
File: AddTests.java
private static int roundAway(BigDecimal b1, BigDecimal b2) { int failures = 0; b1.precision(); b2.precision(); BigDecimal b1_negate = b1.negate(); BigDecimal b2_negate = b2.negate(); b1_negate.precision(); b2_negate.precision(); failures += roundAway1(b1, b2); failures += roundAway1(b1, b2_negate); failures += roundAway1(b1_negate, b2); failures += roundAway1(b1_negate, b2_negate); return failures; }
73. AddTests#precisionConsistencyTest()
Project: openjdk
File: AddTests.java
File: AddTests.java
/** * Verify calling the precision method should not change the * computed result. */ private static int precisionConsistencyTest() { int failures = 0; MathContext mc = new MathContext(1, RoundingMode.DOWN); //value is equivalent to 19990 BigDecimal a = BigDecimal.valueOf(1999, -1); BigDecimal sum1 = a.add(BigDecimal.ONE, mc); a.precision(); BigDecimal sum2 = a.add(BigDecimal.ONE, mc); if (!sum1.equals(sum2)) { failures++; System.out.println("Unequal sums after calling precision!"); System.out.print("Before:\t"); printAddition(a, BigDecimal.ONE, sum1.toString()); System.out.print("After:\t"); printAddition(a, BigDecimal.ONE, sum2.toString()); } return failures; }
74. AddTests#simpleTests()
Project: jdk7u-jdk
File: AddTests.java
File: AddTests.java
/** * Test for some simple additions, particularly, it will test * the overflow case. */ private static int simpleTests() { int failures = 0; BigDecimal[] bd1 = { new BigDecimal(new BigInteger("7812404666936930160"), 11), new BigDecimal(new BigInteger("7812404666936930160"), 12), new BigDecimal(new BigInteger("7812404666936930160"), 13) }; BigDecimal bd2 = new BigDecimal(new BigInteger("2790000"), 1); BigDecimal[] expectedResult = { new BigDecimal("78403046.66936930160"), new BigDecimal("8091404.666936930160"), new BigDecimal("1060240.4666936930160") }; for (int i = 0; i < bd1.length; i++) { if (!bd1[i].add(bd2).equals(expectedResult[i])) failures++; } return failures; }
75. CustomBigDecimalComparator#compare()
Project: javers
File: CustomBigDecimalComparator.java
File: CustomBigDecimalComparator.java
@Override public ValueChange compare(BigDecimal left, BigDecimal right, GlobalId affectedId, Property property) { BigDecimal leftRounded = left.setScale(significantDecimalPlaces, ROUND_HALF_UP); BigDecimal rightRounded = right.setScale(significantDecimalPlaces, ROUND_HALF_UP); if (leftRounded.equals(rightRounded)) { return null; } return new ValueChange(affectedId, property.getName(), left, right); }
76. DecimalConvertTest#testWithList()
Project: jackrabbit
File: DecimalConvertTest.java
File: DecimalConvertTest.java
private void testWithList(ArrayList<BigDecimal> list) { // add negative values for (BigDecimal d : new ArrayList<BigDecimal>(list)) { list.add(d.negate()); } Collections.sort(list); BigDecimal lastDecimal = null; String lastString = null; for (BigDecimal d : list) { String s = DecimalField.decimalToString(d); if (lastDecimal != null) { int compDecimal = (int) Math.signum(lastDecimal.compareTo(d)); int compString = (int) Math.signum(lastString.compareTo(s)); if (compDecimal != compString) { assertEquals(compDecimal, compString); } } BigDecimal test = DecimalField.stringToDecimal(s); if (test.compareTo(d) != 0) { assertEquals(d + "<>" + test.toPlainString(), 0, test.compareTo(d)); } lastDecimal = d; lastString = s; } }
77. BigDecimalTest#test_stripTrailingZero()
Project: j2objc
File: BigDecimalTest.java
File: BigDecimalTest.java
/** * @tests java.math.BigDecimal#stripTrailingZero(long) */ public void test_stripTrailingZero() { BigDecimal sixhundredtest = new BigDecimal("600.0"); assertTrue("stripTrailingZero failed for 600.0", ((sixhundredtest.stripTrailingZeros()).scale() == -2)); /* Single digit, no trailing zero, odd number */ BigDecimal notrailingzerotest = new BigDecimal("1"); assertTrue("stripTrailingZero failed for 1", ((notrailingzerotest.stripTrailingZeros()).scale() == 0)); /* Zero */ //regression for HARMONY-4623, NON-BUG DIFF with RI BigDecimal zerotest = new BigDecimal("0.0000"); assertTrue("stripTrailingZero failed for 0.0000", ((zerotest.stripTrailingZeros()).scale() == 0)); }
78. BigDecimalTest#test_longValue()
Project: j2objc
File: BigDecimalTest.java
File: BigDecimalTest.java
/** * @tests java.math.BigDecimal#longValue() */ public void test_longValue() { BigDecimal long1 = new BigDecimal(value2.negate(), 0); assertTrue("the long value of 12334560000 is not 12334560000", long1.longValue() == -12334560000L); long1 = new BigDecimal(-1345.348E-123D); assertTrue("the long value of -1345.348E-123D is not zero", long1.longValue() == 0); long1 = new BigDecimal("31323423423419083091823091283933"); // ran JDK and found representation for the above was // -5251313250005125155 assertTrue("the long value of 31323423423419083091823091283933 is wrong", long1.longValue() == -5251313250005125155L); }
79. BigDecimalTest#test_ConstructorLjava_lang_String()
Project: j2objc
File: BigDecimalTest.java
File: BigDecimalTest.java
/** * @tests java.math.BigDecimal#BigDecimal(java.lang.String) */ public void test_ConstructorLjava_lang_String() throws NumberFormatException { BigDecimal big = new BigDecimal("345.23499600293850"); assertTrue("the BigDecimal value is not initialized properly", big.toString().equals("345.23499600293850") && big.scale() == 14); big = new BigDecimal("-12345"); assertTrue("the BigDecimal value is not initialized properly", big.toString().equals("-12345") && big.scale() == 0); big = new BigDecimal("123."); assertTrue("the BigDecimal value is not initialized properly", big.toString().equals("123") && big.scale() == 0); new BigDecimal("1.234E02"); }
80. BigDecimalCompareTest#testMinUnequal2()
Project: j2objc
File: BigDecimalCompareTest.java
File: BigDecimalCompareTest.java
/** * min() for unequal BigDecimals */ public void testMinUnequal2() { String a = "92948782094488478231212478987482988429808779810457634781384756794987"; int aScale = 41; String b = "94488478231212478987482988429808779810457634781384756794987"; int bScale = 41; String c = "94488478231212478987482988429808779810457634781384756794987"; int cScale = 41; BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale); BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale); BigDecimal cNumber = new BigDecimal(new BigInteger(c), cScale); assertEquals("incorrect value", cNumber, aNumber.min(bNumber)); }
81. BigDecimalCompareTest#testMinUnequal1()
Project: j2objc
File: BigDecimalCompareTest.java
File: BigDecimalCompareTest.java
/** * min() for unequal BigDecimals */ public void testMinUnequal1() { String a = "92948782094488478231212478987482988429808779810457634781384756794987"; int aScale = 24; String b = "92948782094488478231212478987482988429808779810457634781384756794987"; int bScale = 41; String c = "92948782094488478231212478987482988429808779810457634781384756794987"; int cScale = 41; BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale); BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale); BigDecimal cNumber = new BigDecimal(new BigInteger(c), cScale); assertEquals("incorrect value", cNumber, aNumber.min(bNumber)); }
82. BigDecimalCompareTest#testMinEqual()
Project: j2objc
File: BigDecimalCompareTest.java
File: BigDecimalCompareTest.java
/** * min() for equal BigDecimals */ public void testMinEqual() { String a = "8478231212478987482988429808779810457634781384756794987"; int aScale = 41; String b = "8478231212478987482988429808779810457634781384756794987"; int bScale = 41; String c = "8478231212478987482988429808779810457634781384756794987"; int cScale = 41; BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale); BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale); BigDecimal cNumber = new BigDecimal(new BigInteger(c), cScale); assertEquals("incorrect value", cNumber, aNumber.min(bNumber)); }
83. BigDecimalCompareTest#testMaxUnequal2()
Project: j2objc
File: BigDecimalCompareTest.java
File: BigDecimalCompareTest.java
/** * max() for unequal BigDecimals */ public void testMaxUnequal2() { String a = "92948782094488478231212478987482988429808779810457634781384756794987"; int aScale = 41; String b = "94488478231212478987482988429808779810457634781384756794987"; int bScale = 41; String c = "92948782094488478231212478987482988429808779810457634781384756794987"; int cScale = 41; BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale); BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale); BigDecimal cNumber = new BigDecimal(new BigInteger(c), cScale); assertEquals("incorrect value", cNumber, aNumber.max(bNumber)); }
84. BigDecimalCompareTest#testMaxUnequal1()
Project: j2objc
File: BigDecimalCompareTest.java
File: BigDecimalCompareTest.java
/** * max() for unequal BigDecimals */ public void testMaxUnequal1() { String a = "92948782094488478231212478987482988429808779810457634781384756794987"; int aScale = 24; String b = "92948782094488478231212478987482988429808779810457634781384756794987"; int bScale = 41; String c = "92948782094488478231212478987482988429808779810457634781384756794987"; int cScale = 24; BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale); BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale); BigDecimal cNumber = new BigDecimal(new BigInteger(c), cScale); assertEquals("incorrect value", cNumber, aNumber.max(bNumber)); }
85. BigDecimalCompareTest#testMaxEqual()
Project: j2objc
File: BigDecimalCompareTest.java
File: BigDecimalCompareTest.java
/** * max() for equal BigDecimals */ public void testMaxEqual() { String a = "8478231212478987482988429808779810457634781384756794987"; int aScale = 41; String b = "8478231212478987482988429808779810457634781384756794987"; int bScale = 41; String c = "8478231212478987482988429808779810457634781384756794987"; int cScale = 41; BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale); BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale); BigDecimal cNumber = new BigDecimal(new BigInteger(c), cScale); assertEquals("incorrect value", cNumber, aNumber.max(bNumber)); }
86. BigDecimalArithmeticTest#testRemainderMathContextHALF_DOWN()
Project: j2objc
File: BigDecimalArithmeticTest.java
File: BigDecimalArithmeticTest.java
/** * remainder(BigDecimal, MathContext) */ public void testRemainderMathContextHALF_DOWN() { String a = "3736186567876876578956958765675671119238118911893939591735"; int aScale = -45; String b = "134432345432345748766876876723342238476237823787879183470"; int bScale = 10; int precision = 75; RoundingMode rm = RoundingMode.HALF_DOWN; MathContext mc = new MathContext(precision, rm); String res = "1149310942946292909508821656680979993738625937.2065885780"; int resScale = 10; BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale); BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale); BigDecimal result = aNumber.remainder(bNumber, mc); assertEquals("incorrect quotient value", res, result.toString()); assertEquals("incorrect quotient scale", resScale, result.scale()); }
87. BigDecimalArithmeticTest#testRemainderMathContextHALF_UP()
Project: j2objc
File: BigDecimalArithmeticTest.java
File: BigDecimalArithmeticTest.java
/** * remainder(BigDecimal, MathContext) */ public void testRemainderMathContextHALF_UP() { String a = "3736186567876876578956958765675671119238118911893939591735"; int aScale = 45; String b = "134432345432345748766876876723342238476237823787879183470"; int bScale = 10; int precision = 15; RoundingMode rm = RoundingMode.HALF_UP; MathContext mc = new MathContext(precision, rm); String res = "3736186567876.876578956958765675671119238118911893939591735"; int resScale = 45; BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale); BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale); BigDecimal result = aNumber.remainder(bNumber, mc); assertEquals("incorrect quotient value", res, result.toString()); assertEquals("incorrect quotient scale", resScale, result.scale()); }
88. BigDecimalArithmeticTest#testRemainder2()
Project: j2objc
File: BigDecimalArithmeticTest.java
File: BigDecimalArithmeticTest.java
/** * remainder(BigDecimal) */ public void testRemainder2() { String a = "3736186567876876578956958765675671119238118911893939591735"; int aScale = -45; String b = "134432345432345748766876876723342238476237823787879183470"; int bScale = 10; String res = "1149310942946292909508821656680979993738625937.2065885780"; int resScale = 10; BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale); BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale); BigDecimal result = aNumber.remainder(bNumber); assertEquals("incorrect quotient value", res, result.toString()); assertEquals("incorrect quotient scale", resScale, result.scale()); }
89. BigDecimalArithmeticTest#testRemainder1()
Project: j2objc
File: BigDecimalArithmeticTest.java
File: BigDecimalArithmeticTest.java
/** * remainder(BigDecimal) */ public void testRemainder1() { String a = "3736186567876876578956958765675671119238118911893939591735"; int aScale = 45; String b = "134432345432345748766876876723342238476237823787879183470"; int bScale = 10; String res = "3736186567876.876578956958765675671119238118911893939591735"; int resScale = 45; BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale); BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale); BigDecimal result = aNumber.remainder(bNumber); assertEquals("incorrect quotient value", res, result.toString()); assertEquals("incorrect quotient scale", resScale, result.scale()); }
90. BigDecimalArithmeticTest#testDivideAndRemainderMathContextDOWN()
Project: j2objc
File: BigDecimalArithmeticTest.java
File: BigDecimalArithmeticTest.java
/** * divideAndRemainder(BigDecimal, MathContext) */ public void testDivideAndRemainderMathContextDOWN() { String a = "3736186567876876578956958765675671119238118911893939591735"; int aScale = 45; String b = "134432345432345748766876876723342238476237823787879183470"; int bScale = 20; int precision = 15; RoundingMode rm = RoundingMode.DOWN; MathContext mc = new MathContext(precision, rm); String res = "0E-25"; int resScale = 25; String rem = "3736186567876.876578956958765675671119238118911893939591735"; int remScale = 45; BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale); BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale); BigDecimal result[] = aNumber.divideAndRemainder(bNumber, mc); assertEquals("incorrect quotient value", res, result[0].toString()); assertEquals("incorrect quotient scale", resScale, result[0].scale()); assertEquals("incorrect remainder value", rem, result[1].toString()); assertEquals("incorrect remainder scale", remScale, result[1].scale()); }
91. BigDecimalArithmeticTest#testDivideAndRemainderMathContextUP()
Project: j2objc
File: BigDecimalArithmeticTest.java
File: BigDecimalArithmeticTest.java
/** * divideAndRemainder(BigDecimal, MathContext) */ public void testDivideAndRemainderMathContextUP() { String a = "3736186567876876578956958765675671119238118911893939591735"; int aScale = 45; String b = "134432345432345748766876876723342238476237823787879183470"; int bScale = 70; int precision = 75; RoundingMode rm = RoundingMode.UP; MathContext mc = new MathContext(precision, rm); String res = "277923185514690367474770683"; int resScale = 0; String rem = "1.3032693871288309587558885943391070087960319452465789990E-15"; int remScale = 70; BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale); BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale); BigDecimal result[] = aNumber.divideAndRemainder(bNumber, mc); assertEquals("incorrect quotient value", res, result[0].toString()); assertEquals("incorrect quotient scale", resScale, result[0].scale()); assertEquals("incorrect remainder value", rem, result[1].toString()); assertEquals("incorrect remainder scale", remScale, result[1].scale()); }
92. BigDecimalArithmeticTest#testDivideAndRemainder2()
Project: j2objc
File: BigDecimalArithmeticTest.java
File: BigDecimalArithmeticTest.java
/** * divideAndRemainder(BigDecimal) */ public void testDivideAndRemainder2() { String a = "3736186567876876578956958765675671119238118911893939591735"; int aScale = -45; String b = "134432345432345748766876876723342238476237823787879183470"; int bScale = 70; String res = "2779231855146903674747706830969461168692256919247547952" + "2608549363170374005512836303475980101168105698072946555" + "6862849"; int resScale = 0; String rem = "3.4935796954060524114470681810486417234751682675102093970E-15"; int remScale = 70; BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale); BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale); BigDecimal result[] = aNumber.divideAndRemainder(bNumber); assertEquals("incorrect quotient value", res, result[0].toString()); assertEquals("incorrect quotient scale", resScale, result[0].scale()); assertEquals("incorrect remainder value", rem, result[1].toString()); assertEquals("incorrect remainder scale", remScale, result[1].scale()); }
93. BigDecimalArithmeticTest#testDivideAndRemainder1()
Project: j2objc
File: BigDecimalArithmeticTest.java
File: BigDecimalArithmeticTest.java
/** * divideAndRemainder(BigDecimal) */ public void testDivideAndRemainder1() { String a = "3736186567876876578956958765675671119238118911893939591735"; int aScale = 45; String b = "134432345432345748766876876723342238476237823787879183470"; int bScale = 70; String res = "277923185514690367474770683"; int resScale = 0; String rem = "1.3032693871288309587558885943391070087960319452465789990E-15"; int remScale = 70; BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale); BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale); BigDecimal result[] = aNumber.divideAndRemainder(bNumber); assertEquals("incorrect quotient value", res, result[0].toString()); assertEquals("incorrect quotient scale", resScale, result[0].scale()); assertEquals("incorrect remainder value", rem, result[1].toString()); assertEquals("incorrect remainder scale", remScale, result[1].scale()); }
94. BigDecimalArithmeticTest#testDivideToIntegralValueMathContextDOWN()
Project: j2objc
File: BigDecimalArithmeticTest.java
File: BigDecimalArithmeticTest.java
/** * divideToIntegralValue(BigDecimal, MathContext) */ public void testDivideToIntegralValueMathContextDOWN() { String a = "3736186567876876578956958769675785435673453453653543654354365435675671119238118911893939591735"; int aScale = 45; String b = "134432345432345748766876876723342238476237823787879183470"; int bScale = 70; int precision = 75; RoundingMode rm = RoundingMode.DOWN; MathContext mc = new MathContext(precision, rm); String c = "2.7792318551469036747477068339450205874992634417590178670822889E+62"; int resScale = -1; BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale); BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale); BigDecimal result = aNumber.divideToIntegralValue(bNumber, mc); assertEquals("incorrect value", c, result.toString()); assertEquals("incorrect scale", resScale, result.scale()); }
95. BigDecimalArithmeticTest#testDivideToIntegralValueMathContextUP()
Project: j2objc
File: BigDecimalArithmeticTest.java
File: BigDecimalArithmeticTest.java
/** * divideToIntegralValue(BigDecimal, MathContext) */ public void testDivideToIntegralValueMathContextUP() { String a = "3736186567876876578956958765675671119238118911893939591735"; int aScale = 45; String b = "134432345432345748766876876723342238476237823787879183470"; int bScale = 70; int precision = 32; RoundingMode rm = RoundingMode.UP; MathContext mc = new MathContext(precision, rm); String c = "277923185514690367474770683"; int resScale = 0; BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale); BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale); BigDecimal result = aNumber.divideToIntegralValue(bNumber, mc); assertEquals("incorrect value", c, result.toString()); assertEquals("incorrect scale", resScale, result.scale()); }
96. BigDecimalArithmeticTest#testDivideToIntegralValue()
Project: j2objc
File: BigDecimalArithmeticTest.java
File: BigDecimalArithmeticTest.java
/** * divideToIntegralValue(BigDecimal) */ public void testDivideToIntegralValue() { String a = "3736186567876876578956958765675671119238118911893939591735"; int aScale = 45; String b = "134432345432345748766876876723342238476237823787879183470"; int bScale = 70; String c = "277923185514690367474770683"; int resScale = 0; BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale); BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale); BigDecimal result = aNumber.divideToIntegralValue(bNumber); assertEquals("incorrect value", c, result.toString()); assertEquals("incorrect scale", resScale, result.scale()); }
97. BigDecimalArithmeticTest#testDivideBigDecimalScaleMathContextHALF_EVEN()
Project: j2objc
File: BigDecimalArithmeticTest.java
File: BigDecimalArithmeticTest.java
/** * divide(BigDecimal, MathContext) */ public void testDivideBigDecimalScaleMathContextHALF_EVEN() { String a = "3736186567876876578956958765675671119238118911893939591735"; int aScale = 45; String b = "134432345432345748766876876723342238476237823787879183470"; int bScale = 70; int precision = 21; RoundingMode rm = RoundingMode.HALF_EVEN; MathContext mc = new MathContext(precision, rm); String c = "2.77923185514690367475E+26"; int resScale = -6; BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale); BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale); BigDecimal result = aNumber.divide(bNumber, mc); assertEquals("incorrect value", c, result.toString()); assertEquals("incorrect scale", resScale, result.scale()); }
98. BigDecimalArithmeticTest#testDivideBigDecimalScaleMathContextHALF_DOWN()
Project: j2objc
File: BigDecimalArithmeticTest.java
File: BigDecimalArithmeticTest.java
/** * divide(BigDecimal, MathContext) */ public void testDivideBigDecimalScaleMathContextHALF_DOWN() { String a = "3736186567876876578956958765675671119238118911893939591735"; int aScale = 45; String b = "134432345432345748766876876723342238476237823787879183470"; int bScale = 70; int precision = 21; RoundingMode rm = RoundingMode.HALF_DOWN; MathContext mc = new MathContext(precision, rm); String c = "2.77923185514690367475E+26"; int resScale = -6; BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale); BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale); BigDecimal result = aNumber.divide(bNumber, mc); assertEquals("incorrect value", c, result.toString()); assertEquals("incorrect scale", resScale, result.scale()); }
99. BigDecimalArithmeticTest#testDivideBigDecimalScaleMathContextHALF_UP()
Project: j2objc
File: BigDecimalArithmeticTest.java
File: BigDecimalArithmeticTest.java
/** * divide(BigDecimal, MathContext) */ public void testDivideBigDecimalScaleMathContextHALF_UP() { String a = "3736186567876876578956958765675671119238118911893939591735"; int aScale = 45; String b = "134432345432345748766876876723342238476237823787879183470"; int bScale = 70; int precision = 21; RoundingMode rm = RoundingMode.HALF_UP; MathContext mc = new MathContext(precision, rm); String c = "2.77923185514690367475E+26"; int resScale = -6; BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale); BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale); BigDecimal result = aNumber.divide(bNumber, mc); assertEquals("incorrect value", c, result.toString()); assertEquals("incorrect scale", resScale, result.scale()); }
100. BigDecimalArithmeticTest#testDivideBigDecimalScaleMathContextFLOOR()
Project: j2objc
File: BigDecimalArithmeticTest.java
File: BigDecimalArithmeticTest.java
/** * divide(BigDecimal, MathContext) */ public void testDivideBigDecimalScaleMathContextFLOOR() { String a = "3736186567876876578956958765675671119238118911893939591735"; int aScale = 15; String b = "748766876876723342238476237823787879183470"; int bScale = 70; int precision = 21; RoundingMode rm = RoundingMode.FLOOR; MathContext mc = new MathContext(precision, rm); String c = "4.98978611802562512995E+70"; int resScale = -50; BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale); BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale); BigDecimal result = aNumber.divide(bNumber, mc); assertEquals("incorrect value", c, result.toString()); assertEquals("incorrect scale", resScale, result.scale()); }