[bigDecimal-x-int] Multiply a BigDecimal By an Integer in Java (#13320)

This commit is contained in:
Kai Yuan 2023-01-23 17:41:19 +01:00 committed by GitHub
parent 189904b6d7
commit 0162d98907
1 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,22 @@
package com.baeldung.bigdecimaltimesint;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.math.BigDecimal;
import org.junit.jupiter.api.Test;
public class BigDecimalxIntegerUnitTest {
private static final BigDecimal BIG = new BigDecimal("42.42");
private static final int INT = 10;
private static final BigDecimal EXPECTED = new BigDecimal("424.2");
@Test
void givenBigDecimalAndInt_whenTimes_thenGetExpectedResult() {
BigDecimal result = BIG.multiply(BigDecimal.valueOf(INT));
assertEquals(0, EXPECTED.compareTo(result));
assertThat(result).isEqualByComparingTo(EXPECTED);
}
}