File tree Expand file tree Collapse file tree
main/java/com/baeldung/maths
test/java/com/baeldung/maths Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .baeldung .maths ;
2+
3+ import java .math .BigDecimal ;
4+ import java .math .RoundingMode ;
5+
6+ public class BigDecimalImpl {
7+
8+ public static void main (String [] args ) {
9+
10+ BigDecimal serviceTax = new BigDecimal ("56.0084578639" );
11+ serviceTax = serviceTax .setScale (2 , RoundingMode .CEILING );
12+
13+ BigDecimal entertainmentTax = new BigDecimal ("23.00689" );
14+ entertainmentTax = entertainmentTax .setScale (2 , RoundingMode .FLOOR );
15+
16+ BigDecimal totalTax = serviceTax .add (entertainmentTax );
17+ }
18+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .maths ;
2+
3+ import java .math .BigInteger ;
4+
5+ public class BigIntegerImpl {
6+
7+ public static void main (String [] args ) {
8+
9+ BigInteger numStarsMilkyWay = new BigInteger ("8731409320171337804361260816606476" );
10+ BigInteger numStarsAndromeda = new BigInteger ("5379309320171337804361260816606476" );
11+
12+ BigInteger totalStars = numStarsMilkyWay .add (numStarsAndromeda );
13+
14+ }
15+
16+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .maths ;
2+
3+ import java .math .BigDecimal ;
4+ import java .math .RoundingMode ;
5+ import org .junit .Assert ;
6+ import org .junit .Test ;
7+
8+ public class BigDecimalImplTest {
9+
10+ @ Test
11+ public void givenBigDecimalNumbers_whenAddedTogether_thenGetExpectedResult () {
12+ BigDecimal serviceTax = new BigDecimal ("56.0084578639" );
13+ serviceTax = serviceTax .setScale (2 , RoundingMode .CEILING );
14+
15+ BigDecimal entertainmentTax = new BigDecimal ("23.00689" );
16+ entertainmentTax = entertainmentTax .setScale (2 , RoundingMode .FLOOR );
17+
18+ BigDecimal totalTax = serviceTax .add (entertainmentTax );
19+ BigDecimal result = BigDecimal .valueOf (79.01 );
20+
21+ Assert .assertEquals (result , totalTax );
22+
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .maths ;
2+
3+ import java .math .BigInteger ;
4+
5+ import org .junit .Assert ;
6+
7+ import org .junit .Test ;
8+
9+ public class BigIntegerImplTest {
10+
11+ @ Test
12+ public void givenBigIntegerNumbers_whenAddedTogether_thenGetExpectedResult () {
13+ BigInteger numStarsMilkyWay = new BigInteger ("8731409320171337804361260816606476" );
14+ BigInteger numStarsAndromeda = new BigInteger ("5379309320171337804361260816606476" );
15+
16+ BigInteger totalStars = numStarsMilkyWay .add (numStarsAndromeda );
17+ BigInteger result = new BigInteger ("14110718640342675608722521633212952" );
18+
19+ Assert .assertEquals (result , totalStars );
20+ }
21+
22+ }
You can’t perform that action at this time.
0 commit comments