Search code examples
javaresourcebundle

Integer gets formatted with commas when it gets fetched from a ResourceBundle


year.of.birth={0} was born on {1}

If I pass 2000 or 2008 to {1} the value gets parsed as 2,000 or 2,008. 

I don't want the commas as part of my translated string. How should I avoid this?


Solution

  • The easy way is to pass them as Strings:

    msg.format("year.of.birth", name,  String.valueOf(2008));
    

    An alternative is to specify the number format in the message resource (but I would only do that if the format can vary between locales):

    year.of.birth={0} was born in {1,number,####}