语言环境无关紧要

语言环境无关紧要

本文介绍了获取仅一个字符的货币符号(例如$,₹等)(语言环境无关紧要)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有货币代码(例如USD,INR等).我只想获取这些代码中只有一个字母的符号(例如$,₹等).我试图找到许多解决方案,例如,但是它没有对我不起作用.我正在使用以下代码

i have currency code (e.g. USD,INR,etc...). I want to get symbols of only one letter of those codes (e.g $,₹, etc). i have tried to find many solutions like this but it doesn't works for me. i am using code as below

var pound = Currency.getInstance("GBP");
var symbol = pound.getSymbol();

,但返回的符号为(卢比,美元,澳元等).我只想获得一个如上所述的字符符号.我知道符号取决于它们的语言环境,但是我想获得与它们的语言环境无关的符号.

but it returns symbols like (Rs., US$, AU$, etc...). i want to get only one character symbol as mentioned above. i know that symbols are dependent on their locale but i want to get symbols independent from their locale.

推荐答案

尝试像getSymbol(Locale.getDefault(Locale.Category.DISPLAY))一样在getSymbol()中调用默认的Locale,检查下面的代码

try to calling default Locale in getSymbol() like getSymbol(Locale.getDefault(Locale.Category.DISPLAY)) check below code

Currency pound = Currency.getInstance("GBP");
pound.getSymbol(Locale.getDefault(Locale.Category.DISPLAY));

这篇关于获取仅一个字符的货币符号(例如$,₹等)(语言环境无关紧要)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 10:11