Reputation: 2411
Is there a way to probe an ICU Currency Locale for it's minimal denomination? For example US's would be $0.01, Korea (ko_KR) would be ₩1. I thought calling getRoundingIncrement()
on the DecimalFormat
object may give it to me but that returns 0 for both en_US and ko_KR.
Upvotes: 0
Views: 356
Reputation: 2411
Thank you to Steve Loomis and Artyom for helping me piece together a solution.
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;
}
Upvotes: 0
Reputation: 31243
You need to take a look on: getMinimumFractionDigits()
function:
#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;
}
This is the output of the program for different locales, seems it is what you need
$ ./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 руб.
Upvotes: 1