Reputation: 137
I have a string and im trying to format it into a decimal format so that there is a , every 3 numbers using the decimal format class but im having troble. Here is my code
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 is from a text document and is the number 6486 in this instance but in others using the same code it gets all the way up to 301122. With this method I want to turn these numbers into things such as 6,486 or 301,112 my constructor statement my IDE is telling my in it that ")"is expected I'm also not sure how to change my decimal format back into a string once I format my number.
Upvotes: 0
Views: 234
Reputation: 10260
You missed a comma there after the myNum. Also, it should be
DecimalFormat formNum = new DecimalFormat("000,000");
return formNum.format(myNum);
Upvotes: 2