How to change the decimal separator of DecimalFormat from comma to dot/point?

10/14 04:29
阅读数 0

问题:

I have this little crazy method that converts BigDecimal values into nice and readable Strings.我有这个疯狂的小方法,可以将 BigDecimal 值转换为漂亮且可读的字符串。

private String formatBigDecimal(BigDecimal bd){
    DecimalFormat df = new DecimalFormat();
    df.setMinimumFractionDigits(3);
    df.setMaximumFractionDigits(3);
    df.setMinimumIntegerDigits(1);
    df.setMaximumIntegerDigits(3);
    df.setGroupingSize(20);
    return df.format(bd);
}

It however, also produces a so called grouping separator "," that makes all my values come out like this:然而,它也会产生一个所谓的分组分隔符"," ,这使得我的所有值都像这样:

xxx,xxx

I do need the separator to be a dot or a point and not a comma.我确实需要分隔符是点或点而不是逗号。 Does anybody have a clue of how to accomplish this little feat?有没有人知道如何完成这个小壮举?

I have read this and in particular this to death now but I cannot find a way to get this done.我现在已经阅读了这篇文章,尤其是这篇文章,但我找不到完成这项工作的方法。 Am I approaching this the wrong way?我是否以错误的方式接近这个? Is there a much more elegant way of doing this?有没有更优雅的方式来做到这一点? Maybe even a solution that accounts for different local number representations, since the comma would be perfect by European standards.甚至可能是一个解决不同本地数字表示的解决方案,因为逗号按照欧洲标准是完美的。


解决方案:

参考一: https://en.stackoom.com/question/LCoG
参考二: https://stackoom.com/question/LCoG
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部