Best code examples for Java 8 BigDecimal class (java.math.BigDecimal)

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 BigDecimal class.
You can now enable Codota on your own code to easily search and navigate your Java codebase.

Java 8 BigDecimal examples from Open Source projects
This code example shows how to use the following methods:
33:	BigDecimal expected = new BigDecimal("123456789123456789.987654321"); 
-
36:	ByteBuffer buffer = decimal.serialize(expected); 
-
38:	Assert.assertEquals(expected, actual); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods:
58:	decimal = new BigDecimal(source); 
-
65:	return decompose(decimal); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods: toString
651:	BigDecimal bd = new BigDecimal(a); 
652:	fail("NumberFormatException has not been caught: " + bd.toString()); 
Full Snippet Info
8
CodeRank
This code example shows how to use the following methods:
68:	BigDecimal right = new BigDecimal(number); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: compareTo, precision, scale, setScale, stripTrailingZeros
88:	BigDecimal bd = normalize(new BigDecimal(bi), true); 
-
217:	if (d.compareTo(BigDecimal.ZERO) == 0) { 
-
221:	d = d.stripTrailingZeros(); 
222:	if (d.scale() < 0) { 
-
224:	d = d.setScale(0); 
-
237:	int intDigits = bd.precision() - bd.scale(); 
-
243:	int maxScale = Math.min(MAX_SCALE, Math.min(MAX_PRECISION - intDigits, bd.scale())); 
244:	if (bd.scale() > maxScale ) { 
-
246:	bd = bd.setScale(maxScale, RoundingMode.HALF_UP); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: add, subtract
74:	BigDecimal i = new BigDecimal("100.5"); 
-
77:	user.setMoney(i); 
-
79:	i = i.subtract(BigDecimal.valueOf(50)); 
-
81:	i = i.add(BigDecimal.valueOf(25)); 
-
88:	assertEquals(user.getMoney(), i); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: equals
39:	if (!value.equals(monetaryAmount.value)) return false; 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: divide
76:	return ((BigDecimal) l).divide(new BigDecimal(r.intValue()), RoundingMode.HALF_UP); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: divide, multiply, scale, setScale
179:	value = value.multiply(_factor); 
-
181:	int scale = _scale == null ? value.scale() : _scale.intValue(); 
182:	value = value.divide(_factor, scale, BigDecimal.ROUND_HALF_EVEN); 
-
254:	if(newValue.scale() == 0) { 
255:	newValue = newValue.setScale(4); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: compareTo
36:	BigDecimal v = new BigDecimal ( "-1" ); 
-
80:	is1_7OorLater = version.compareTo ( new BigDecimal ( "1.7" )) >=0; 
81:	is1_7 = version.compareTo ( new BigDecimal ( "1.7" ))==0; 
82:	is1_8 = version.compareTo ( new BigDecimal ( "1.8" ))==0; 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods:
36:	account.profit(new BigDecimal(1000), DateTime.now().plusMillis(1)); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: multiply
76:	return ((BigDecimal) l).multiply(new BigDecimal(r.intValue())); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods:
69:	BigDecimal bdOne = new BigDecimal("1"); 
-
72:	assertTrue(comparator.compare(bdOne, bdTwo) < 0); 
73:	assertTrue(comparator.compare(bdOne, new BigDecimal("1")) == 0); 
74:	assertTrue(comparator.compare(bdTwo, bdOne) > 0); 
-
77:	assertTrue(comparator.compare(1, bdOne) == 0); 
78:	assertTrue(comparator.compare(2, bdOne) > 0); 
-
81:	assertTrue(comparator.compare(1.0d, bdOne) == 0); 
82:	assertTrue(comparator.compare(2.0d, bdOne) > 0); 
-
85:	assertTrue(comparator.compare(1.0f, bdOne) == 0); 
86:	assertTrue(comparator.compare(2.0f, bdOne) > 0); 
-
89:	assertTrue(comparator.compare(1L, bdOne) == 0); 
90:	assertTrue(comparator.compare(2L, bdOne) > 0); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: divide
103:	return numerator.divide(denominator); 
-
105:	return numerator.divide(denominator, BigDecimal.ROUND_HALF_UP); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: remainder
73:	return ((BigDecimal) l).remainder(new BigDecimal(r.longValue())); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods:
109:	multipleShareTrade.setConditions(new Conditions(new BigDecimal(10), new BigDecimal(0.01))); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: add
39:	currentAmount = currentAmount.add(amount); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: add, multiply, setScale, signum, subtract
65:	} 
-
73:	"true".equals(LibFormulaBoot.getInstance().getGlobalConfig().getConfigProperty 
-
75:	return getExcelDate(date, excelBugCompatible, computeZeroDate(dateSystem, excelBugCompatible)); 
-
80:	final int zeroDate) 
-
176:	final BigDecimal fractionNum = date.subtract(wholeDays); 
177:	final BigDecimal fraction = fractionNum.multiply(DAY_MILLISECONDS); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: add, setScale, signum
65:	return n.setScale(0); 
-
73:	if(n.signum()<0) 
-
80:	n = n.add(DELTA); 
81:	round = n.setScale(1, BigDecimal.ROUND_DOWN); 
82:	return round.setScale(0, BigDecimal.ROUND_DOWN); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: divide, precision, scale, setScale
62:	return bigLeft.divide(bigRight); 
-
65:	int precision = Math.max(bigLeft.precision(), bigRight.precision()) + DIVISION_EXTRA_PRECISION; 
66:	BigDecimal result = bigLeft.divide(bigRight, new MathContext(precision)); 
67:	int scale = Math.max(Math.max(bigLeft.scale(), bigRight.scale()), DIVISION_MIN_SCALE); 
68:	if (result.scale() > scale) result = result.setScale(scale, BigDecimal.ROUND_HALF_UP); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods:
163:	objValue = new BigDecimal(objValue.toString()); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: precision, scale, setScale, unscaledValue
82:	return decimal.unscaledValue().longValue(); 
-
98:	BigDecimal decimal = new BigDecimal(buffer, 0, length); 
-
100:	checkState(decimal.scale() <= type.getScale(), "Read decimal value scale larger than column scale"); 
101:	decimal = decimal.setScale(type.getScale(), HALF_UP); 
102:	checkState(decimal.precision() <= type.getPrecision(), "Read decimal precision larger than column precision"); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: movePointRight, scale, scaleByPowerOfTen
55:	BigDecimal a = new BigDecimal("12345.6789012345678901234567890123456789"); 
56:	BigDecimal res = a.movePointRight(10); 
57:	assertEquals("incorrect scale", 24, res.scale()); 
-
59:	res = a.scaleByPowerOfTen(-50); 
60:	assertEquals("incorrect scale", 84, res.scale()); 
-
62:	res = a.scaleByPowerOfTen(50); 
63:	assertEquals("incorrect scale", -16, res.scale()); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods:
30:	BigDecimal loanAmount = new BigDecimal("1234"); 
-
32:	CashFlowForm cashFlowForm = cashFlowController.prepareCashFlowForm(2012, 1, 12, loanAmount, indebtednessRatio, true); 
33:	CashFlowForm expectedCashFlowForm = new CashFlowForm(cashFlowDetail, true, loanAmount, indebtednessRatio); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: add
40:	normalised = units.scaleTo(value, units.getBaseUnits()); 
-
136:	return new Amount<Q>(value.add(other.value), units); 
-
139:	return new Amount<Q>(value.add(other.units.scaleTo(other.value, units)), units); 
-
141:	return new Amount<Q>(units.scaleTo(value, other.units).add(other.value), other.units); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: subtract
76:	return ((BigDecimal) l).subtract(new BigDecimal(r.intValue())); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods:
21:	this.ratio = new BigDecimal(ratio); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods:
36:	private static BigDecimal zero = new BigDecimal("0.0"); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: doubleValue, round
21:	BigDecimal bd = new BigDecimal(tmp); 
-
23:	bd = bd.round(mathContext); 
24:	result = bd.doubleValue(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: divide
22:	return new BigDecimal(priceInCents).divide(new BigDecimal(100)).setScale(SCALE, 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: multiply
86:	b = b.multiply(new BigDecimal(factor)); 
87:	return super.format(b, arg1, arg2); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods:
43:	assertTrue(cmpEq.matches(new BigDecimal("5"))); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods:
100:	ret = new BigDecimal(balance); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods: doubleValue, round
25:	BigDecimal result = new BigDecimal(tmp); 
-
27:	result = result.round(mathContext); 
-
29:	return result.doubleValue(); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods:
75:	return TotalGroupSumQuotientPercentFunction.ONE_HUNDRED.multiply(new BigDecimal(String.valueOf(value))); 
Full Snippet Info
7
CodeRank
This code example shows how to use the following methods:
82:	this(currency, new BigDecimal(amount)); 
Full Snippet Info
7
CodeRank
Related Java 8 BigDecimal Questions & Answers:
See Code Examples for Java 8 BigDecimal Methods: