I have the following JSON example below:
{
"value": 946.2,
"description": "O valor é R$ 946,20."
}
I need to use MessageFormat to JUnit test this JSON example, but I get an invalid value because my Locale is not in english. If I change my Locale to english instead of brazilian portuguese I get an invalid description because the currency value is displayed in English.
Here's my code:
import java.math.BigDecimal;
import java.text.MessageFormat;
import java.util.Locale;
Locale.setDefault(Locale.ENGLISH);
System.out.println(MessageFormat.format("""
'{'
"value": {0},
"description": "O valor é {0,number,currency}."
'}'
""", new BigDecimal(946.2)));
How can I format the value or the description in order to get the JSON as displayed above?
This is a
String.formatsolution with two inner (localized, customized)NumberFormatters:Prints: