gpt4 book ai didi

c++ - ICU 货币区域获取面额

转载 作者:行者123 更新时间:2023-11-28 08:23:30 24 4
gpt4 key购买 nike

有没有办法探测 ICU最小面额的货币区域设置?例如,美国为 0.01 美元,韩国 (ko_KR) 为 ₩1。我想在 DecimalFormat object 上调用 getRoundingIncrement()可以给我,但是对于 en_US 和 ko_KR 都返回 0。

最佳答案

您需要查看: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 руб.

关于c++ - ICU 货币区域获取面额,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4948986/

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