NumberFormat中的小数分隔符 [英] Decimal separator in NumberFormat

查看:160
本文介绍了NumberFormat中的小数分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个locale java.text.NumberFormat:

Given a locale java.text.NumberFormat:

NumberFormat numberFormat = NumberFormat.getInstance();

我如何获得用作十进制分隔符的字符(如果它是逗号或点) NumberFormat的?如何在不使用新的DecimalFormat(格式)的情况下修改此属性?

How can I get the character used as Decimal separator (if it's a comma or a point) in that numberformat? How can I modify this property without having to use new DecimalFormat(format)?

谢谢

推荐答案

助手类 DecimalFomatSymbols 正在寻找:

DecimalFormat format=DecimalFormat.getInstance();
DecimalFormatSymbols symbols=format.getDecimalFormatSymbols();
char sep=symbols.getDecimalSeparator();

根据需要设置符号:

//create a new instance
DecimalFormatSymbols custom=new DecimalFormatSymbols();
custom.setDecimalSeparator(',');
format.setDecimalFormatSymbols(custom);

编辑:此答案仅对有效DecimalFormat ,而不是问题中所需的 NumberFormat 。无论如何,因为它可以帮助作者,我会在这里让它。

this answer is only valid for DecimalFormat, and not for NumberFormat as required in the question. Anyway, as it may help the author, I'll let it here.

这篇关于NumberFormat中的小数分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆