java - Adding char in a specific string location -
hello i'm beginner in java , have problem adding comma on string of digits example 1000 1,000 in output .
i can use :
string digitswithcomma = ""; digitswithcomma = str.substring(0,1) + "," + str.substring(1);
but problem works on thousand not on higher digits. can please me this
java has concept called number formatting seems you're doing:
import java.text.numberformat; string output = numberformat.getnumberinstance(locale.us).format(1000000); since gave locale, print out 1,000,000.
generally speaking, if find wondering "how can implement x feature?" chances java has standard or built-in way of doing it, if you're dealing formatting of kind.
Comments
Post a Comment