gpt4 book ai didi

java - 为什么 IDR 的 Currency.defaultFractionDigits() 是 0 for android?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:11:30 29 4
gpt4 key购买 nike

对于印尼货币 (IDR),defaultFractionDigits() 在 Android 应用中为我提供 0

Locale locale = new Locale("in", "ID");
Currency currency = Currency.getInstance(locale);
Log.d("TEST",String.format(locale, "Currency - %s ( %s ) Decimal - %s ",
currency.getSymbol(locale),
currency.getSymbol(),
currency.getDefaultFractionDigits()));

D/TEST: Currency - Rp ( IDR ) Decimal - 0

当我在我的 eclipse 中测试它时,Same 给了我 2(也在 RexTester 中)

Locale.setDefault(new Locale("in","ID"));
Currency c = Currency.getInstance("IDR");
System.out.println("Symbol: " + c.getSymbol());
System.out.println("Default fractional digits: " + c.getDefaultFractionDigits());

Symbol: Rp

Default fractional digits: 2

两者的文档Android & Java声明它是 ISO 4217(ISO 4217:2015 列出了带有两位小数点的 IDR)

为什么 Android 应用程序为 0

最佳答案

我在我的 Android Studio 3.0.1 中使用 JRE 1.8.0_152 运行了这个 jUnit 代码:

@Test
public void defaultFractionDigits_isCorrect() throws Exception {
Locale locale = new Locale("in", "ID");
Currency currency = Currency.getInstance(locale);
assertEquals(2, currency.getDefaultFractionDigits());
}

@Test
public void defaultFractionDigits2_isCorrect() throws Exception {
Locale locale = new Locale("in", "ID");
Currency currency = Currency.getInstance(locale);
assertEquals("Currency - Rp ( IDR ) Decimal - 2 ",
String.format(locale, "Currency - %s ( %s ) Decimal - %s ",
currency.getSymbol(locale),
currency.getSymbol(),
currency.getDefaultFractionDigits()));
}

两个测试都通过了。然后我运行了这个测试来检查你得到的结果:

@Test
public void defaultFractionDigits3_isCorrect() throws Exception {
Locale locale = new Locale("in", "ID");
Currency currency = Currency.getInstance(locale);
assertEquals("Currency - Rp ( IDR ) Decimal - 0 ",
String.format(locale, "Currency - %s ( %s ) Decimal - %s ",
currency.getSymbol(locale),
currency.getSymbol(),
currency.getDefaultFractionDigits()));
}

测试失败:

org.junit.ComparisonFailure: 
Expected :Currency - Rp ( IDR ) Decimal - 0
Actual :Currency - Rp ( IDR ) Decimal - 2

所以当我单独测试它时,我看不到你所看到的。所以也许是其他东西把它搞砸了?还是我没答对问题?

更新:

当我在运行 SDK 24 的模拟器(Android 测试)中运行相同的测试时,我得到了与您相同的结果:

expected:<2> but was:<0>
expected:<... ( IDR ) Decimal - [2] > but was:<... ( IDR ) Decimal - [0] >

在实际的 Galaxy S7 上得到相同的结果......似乎那里有东西......

关于java - 为什么 IDR 的 Currency.defaultFractionDigits() 是 0 for android?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49171632/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com