简体   繁体   中英

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. I use it to put a "10,000" on a textfield. 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"? 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. Not 10,000.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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