java - Replacing substring -


public class test {     public static void main(string[] args)     {         string abra = "100000";         abra = abra.replace(abra.substring(abra.length() - 3),                "," + abra.substring(abra.length() - 3));         system.out.println(abra);      } } 

totally new java , i'm trying replace number comma separate zeros three. works fine thousands , ten thousands, i'm getting wierd results more. ideas?

thanks in advance!

because you're manually 6 digits. better approach using numberformat#getnumberinstance locale.us:

a locale object represents specific geographical, political, or cultural region. operation requires locale perform task called locale-sensitive , uses locale tailor information user. example, displaying number locale-sensitive operation— number should formatted according customs , conventions of user's native country, region, or culture.


numberformat.getnumberinstance(locale.us).format(20000000); // 20,000,000 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -