简体   繁体   English

如果用于初始化文本字段的内容是双精度字符,如何在文本字段上加上逗号?

[英]How do I put a comma on a textfield if what is used to initialize the textfield is a double?

How do I put a comma on a textfield if what is used to initialize the textfield is a double? 如果用于初始化文本字段的内容是双精度字符,如何在文本字段上加上逗号?

So, the declared double variable is equal to, lets say, 10,000. 因此,声明的double变量等于10,000。 I use it to put a "10,000" on a textfield. 我用它在文本字段上放置“ 10,000”。 So, this is what I want to happen... 所以,这就是我想要发生的事情...

This kind of result: 这种结果: 这种结果

However, what I get is something like this: 但是,我得到的是这样的:

我得到什么

How do I make the output in the textfield into "24,508.0" (with a comma) instead of just "24508.0"? 如何使文本字段中的输出变为“ 24,508.0”(带逗号)而不是“ 24508.0”? I was thinking, maybe, I could turn it into an array. 我在想,也许可以将它转换成数组。 But how? 但是如何?

You have to use a formatted text field. 您必须使用格式化的文本字段。 Check out this link for more information. 查看此链接以获取更多信息。 I would also like to note that a Boolean is either true or false. 我还要指出,布尔值是true还是false。 Not 10,000. 不是10,000。

double d = 10000000.5
System.out.println(NumberFormat.getNumberInstance(Locale.US).format(d));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM