如何设置空格分隔符以使DecimalFormat浮动? [英] How to set space separator to float DecimalFormat?

查看:147
本文介绍了如何设置空格分隔符以使DecimalFormat浮动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在float中将空格设置为DecimalFormat的千位分隔符?我想将13,52显示为13,5,但是将13,00显示为13,我使用

How to set space as thousand separator for DecimalFormat in float? I want to show 13,52 as 13,5, but 13,00 as 13 and I did this with

new DecimalFormat("#.#").format(fIncome)

但我想1400,5为1400 ,5和1400分别为1400。

but I want to 1400,5 be 1 400,5 and 1400 to be 1 400.

对于重复的代码,我使用以下代码(我不想在dCount中的逗号后显示数字):

For double I use this code (I don't want to shows numbers after comma in dCount):

String.format("%,d", (int)dCount)

但是如何将其用于带有逗号后1个数字的浮点数呢?

But how to use this for floating number with 1 number after comma?

推荐答案

好,我得到了我想要的东西:)

Ok I got what I want :)

new DecimalFormat("###,###.#").format(fIncome)

这篇关于如何设置空格分隔符以使DecimalFormat浮动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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