ICU通貨ロケールの最小額を調べる方法はありますか?たとえば、米国は0.01ドル、韓国(ko_KR)は₩1になります。オブジェクトgetRoundingIncrement()
を呼び出すとそれが得られると思いましたが、en_USとko_KRの両方で0が返されます。DecimalFormat
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
解決策をまとめるのを手伝ってくれたSteveLoomisと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 に答える