【问题标题】:NumberFormat doesn't work as a thousand separator for system locale?NumberFormat 不能用作系统区域设置的千位分隔符?
【发布时间】:2018-03-26 07:47:26
【问题描述】:
// above onCreate
private DecimalFormat decimalFormat =(DecimalFormat) 
NumberFormat.getInstance();

// inside my textWatcher

String[] splitted = originalString.split("((?<=[-+x÷])|(?=[-+.x÷]))");

                StringBuilder formatted = new StringBuilder();

                for (String word : splitted) {
                    try {
                        BigInteger num = new BigInteger(word);
                        formatted.append(decimalFormat.format(num));

                    } catch (NumberFormatException e) {
                        formatted.append(word);
                    }
                }

当我使用尼泊尔语时,我将一个数字作为字符串变量,并希望用千位分隔符(如 2345678)显示为 23,45,678。糟糕的是,代码的工作方式如下 २,३४५,६७८ 为 2345678。

令人惊讶的是,这适用于作为系统语言环境的印地语语言,并且可以显示 23,45,678。为什么不是尼泊尔语??

【问题讨论】:

标签: android locale number-formatting


【解决方案1】:

试试这个代码:

<NumberFormat thousandSeperator="." decimalSeperator="," onKeyDown = {(e) => 
{
const {key, target} = e;
const {selectionStart, value} = target;
if (key === '.') {
 e.preventDefault();
 target.value = `${value.substr(0, 
 selectionStart)},${value.substr(selectionStart, value.length)}`; 
  }
 }}/>

【讨论】:

  • 那是 Javascript 吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-06
  • 2011-07-16
  • 1970-01-01
相关资源
最近更新 更多