Why is jstl's formatNumber currency symbol loc

2019-02-19 14:25发布

问题:

I'm using formatNumber as follows:

<fmt:formatNumber value="${amount}" type="currency" currencyCode="${currencyCode}" var="amt" />

If I'm in locale en_US and the currency code is EUR I get EUR as the symbol, but if I'm in locale en_GB I get . Why is the locale taken into account? Shouldn't EUR always convert into ? Is there anyway to get the behavior I'm expecting using formatNumber?

回答1:

Locale is taken into acount so the output makes sense to the user.

As a silly American (who lives in the en_US locale) I have no idea what that funky symbol means.

EUR makes perfect sense to me.

A quick google suggests you can set the currencySymbol attribute to whatever you want:

<fmt:formatNumber value="${amount}" type="currency" currencySymbol="FOO" currencyCode="${currencyCode}" var="amt" />