I got a service that's sending me the currency ID of the currency I should work with. The ID is a number that represents an ISO-4217 Currency.
The java Currency object enable to get an instance according to the currency string ID (i.e USD, JPY...), but not according to the ISO number code (i.e 840, 392...)
How can I get an instance using the number value?
Maven artifact com.neovisionaries:nv-i18n:1.9 contains CurrencyCode, which is a Java enum listing all ISO 4217 codes. With CurrencyCode, getting a Currency instance from an ISO 4217 numeric code can be written like the following.
import java.util.Currency;
import com.neovisionaries.i18n.CurrencyCode;
public class Test
{
public static void main(String[] args)
{
// Get the Currency instance for 392 (Japanese Yen).
Currency currency
= CurrencyCode.getByCode(392).getCurrency();
// This prints "JPY".
System.out.println("currency = " + currency);
}
}
nv-i18n project page:
https://github.com/TakahikoKawasaki/nv-i18n
Maven:
<dependency>
<groupId>com.neovisionaries</groupId>
<artifactId>nv-i18n</artifactId>
<version>1.9</version>
</dependency>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With