mirror of
https://gitee.com/dromara/hutool.git
synced 2025-06-28 04:35:14 +08:00
Merge pull request #3970 from asukavuuyn/v5-dev
fix(Money): currency scaling bug(币种小数位硬编码)
This commit is contained in:
commit
28b21d7617
@ -294,7 +294,7 @@ public class Money implements Serializable, Comparable<Money> {
|
||||
*/
|
||||
public void setAmount(BigDecimal amount) {
|
||||
if (amount != null) {
|
||||
cent = rounding(amount.movePointRight(2), DEFAULT_ROUNDING_MODE);
|
||||
cent = rounding(amount.movePointRight(currency.getDefaultFractionDigits()), DEFAULT_ROUNDING_MODE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,8 @@ package cn.hutool.core.math;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Currency;
|
||||
|
||||
public class MoneyTest {
|
||||
|
||||
@ -20,4 +22,12 @@ public class MoneyTest {
|
||||
|
||||
assertEquals(1234.56D, MathUtil.centToYuan(123456), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void currencyScalingTest() {
|
||||
Money jpyMoney = new Money(0, Currency.getInstance("JPY"));
|
||||
jpyMoney.setAmount(BigDecimal.ONE);
|
||||
assertEquals(1, jpyMoney.getCent());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user