有没有办法探测ICU货币区域设置的最小面额?例如,美国是 0.01 美元,韩国 (ko_KR) 是 ₩1。我认为调用getRoundingIncrement()
该DecimalFormat
对象可能会将它交给我,但对于 en_US 和 ko_KR 都返回 0。
问问题
286 次
2 回答
1
你需要看看:getMinimumFractionDigits()
函数:
#include <unicode/numfmt.h>
#include <unicode/ustream.h>
#include <unicode/ustring.h>
#include <iostream>
int main()
{
UErrorCode e=U_ZERO_ERROR;
icu::NumberFormat *fmt = icu::NumberFormat::createCurrencyInstance(e);
std::cout << fmt->getMinimumFractionDigits() << std::endl;
icu::UnicodeString str;
std::cout << fmt->format(12345.5678,str) << std::endl;
delete fmt;
}
这是程序针对不同语言环境的输出,似乎是您需要的
$ ./a.out
2
$12,345.57
$ LC_ALL=en_US.UTF-8 ./a.out
2
$12,345.57
$ LC_ALL=ja_JP.UTF-8 ./a.out
0
¥12,346
$ LC_ALL=ko_KR.UTF-8 ./a.out
0
₩12,346
$ LC_ALL=ru_RU.UTF-8 ./a.out
2
12 345,57 руб.
于 2011-02-09T18:46:08.477 回答
0
感谢 Steve Loomis 和 Artyom 帮助我拼凑出一个解决方案。
double roundingIncrement = formatter->getRoundingIncrement();
int32_t minFractionDigits = formatter->getMinimumFractionDigits();
double minDenom;
if (roundingIncrement == 0.0 && minFractionDigits == 0.0)
{
minDenom = 1.0;
}
else if (roundingIncrement != 0.0 && minFractionDigits > 0.0)
{
minDenom = roundingIncrement;
}
else
{
minDenom = 0.01;
}
于 2011-02-11T21:53:36.773 回答