// 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。为什么不是尼泊尔语呢??
发布于 2018-03-26 15:54:28
尝试以下代码:
<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)}`;
}
}}/>https://stackoverflow.com/questions/49486396
复制相似问题