插入逗号成整数 [英] Inserting commas into integers

查看:125
本文介绍了插入逗号成整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Android是有一个简单的方法插入逗号到数字的价值? 也就是说,如果我有一个EditText在它12345,我怎么能显示这是12345?

In Android is there an easy way to insert commas into a numberical value? ie if I have an EditText with 12345 in it, how can I display this as 12,345?

我想我可以使用子串,每3号块之间砍它分为3大块数量串联,然后与答案x个,做到这一点。 这将是pretty的容易的,如果数的长​​度是恒定的,但作为数可能从一个数字到,说20,它使得它更复杂的

I think I can do it using substring and chopping it up into x number of 3 number chunks then concatenating the answer with ',' between each 3 number chunk. This would be pretty easy if length of number was constant, but as the number could be from one digit to, say 20, it makes it more complex.

只是好奇,如果有一个简单,干净的方法之前,我去让我的子解决方案,以实现这一目标。

Just curious if there is a simple and clean way to achieve this before I go about making my substring solution.

干杯

推荐答案

如果爪哇 -

使用这样的:

    double amount = 2324343192.015;
    NumberFormat formatter = new DecimalFormat("###,###,###.##");
    System.out.println("The Decimal Value is: "+formatter.format(amount));

结果:十进制值是:2,324,343,192.02

Result: The Decimal Value is: 2,324,343,192.02

这篇关于插入逗号成整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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