Java格式带德国语言环境的双精度值 [英] Java format double value with german locale

查看:157
本文介绍了Java格式带德国语言环境的双精度值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个1400.0的双精度值,现在我想将此值格式化为Java中的1.400,00.

I have the double value 1400.0 and now I want to format this value into 1.400,00 in Java.

我目前正在这样做:

double doubleValue = 1400.0    
String pattern = "0.00";
DecimalFormat format = (DecimalFormat)NumberFormat.getNumberInstance(Locale.GERMAN)
format .applyPattern(pattern);
// will be 1400,00 and not 1.400,00
String formattedValue = format.format(doubleValue);

我想念什么?

推荐答案

尝试:

String pattern = "#,##0.00";

此模式告诉DecimalFormat将分组字符添加到给定的数字中.

This pattern tells a DecimalFormat to add the grouping character to the given number.

最初我是用零来写的,但这实际上会为小数字创建额外的零.在不需要初始零的位置使用#模式.

Originally I wrote this with zeros, but this would actually create extra zeros for small numbers. Use the # pattern where you don't want initial zeros.

这篇关于Java格式带德国语言环境的双精度值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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