我有一个字符串,我试图将其格式化为十进制格式,以便使用十进制格式类每 3 个数字有一个,但我遇到了问题。这是我的代码
public String getNum()
{
//turn the string myNum into a formatted number so there's a , after every 3 digits
DecimalFormat formNum = new DecimalFormat(myNum "000,000");
//set formNum to a string don't know what method to use for this step
return formNum ;
}
myNum 来自文本文档,在本例中是数字 6486,但在其他使用相同代码的情况下,它一直达到 301122。通过这种方法,我想将这些数字转换为诸如 6,486 或 301,112 我的我的 IDE 告诉我的构造函数语句“)”是预期的,我也不确定如何在格式化数字后将十进制格式更改回字符串。
最佳答案
您在 myNum 后面漏掉了一个逗号。另外,应该是
DecimalFormat formNum = new DecimalFormat("000,000");
return formNum.format(myNum);
关于java - 十进制格式类问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16113893/