如何在Android中格式化国际货币-创新互联-古蔺大橙子建站
RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
如何在Android中格式化国际货币-创新互联

如何在Android中格式化国际货币?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

成都创新互联于2013年创立,是专业互联网技术服务公司,拥有项目网站设计、网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元邛崃做网站,已为上家服务,为邛崃各地企业和个人服务,联系电话:18980820575
class MainActivity : AppCompatActivity() {
 
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
 
    textView1.text = formatCurrency(1f, CURRENCY_US_DOLLARS, LANGUAGE_ENGLISH, COUNTRY_US)
    textView2.text = formatCurrency(1f, CURRENCY_US_DOLLARS, LANGUAGE_ENGLISH, COUNTRY_CANADA)
    textView3.text = formatCurrency(1f, CURRENCY_US_DOLLARS, LANGUAGE_ENGLISH, COUNTRY_AUSTRALIA)
  }
 
  private fun formatCurrency(amount: Float, currency: String, language: String, country: String) =
      currencyInLocale(currency, language, country).format(amount)
 
  private fun currencyInLocale(
      currencyCode: String,
      language: String,
      country: String = "",
      variant: String = ""): NumberFormat =
      Locale(language, country, variant).let {
        NumberFormat.getCurrencyInstance(it).apply {
          currency = Currency.getInstance(currencyCode)
        }
      }
 
  companion object {
    private const val CURRENCY_US_DOLLARS: String = "USD"
    private const val LANGUAGE_ENGLISH: String = "EN"
    private const val COUNTRY_US: String = "US"
    private const val COUNTRY_CANADA: String = "CA"
    private const val COUNTRY_AUSTRALIA: String = "AU"
  }
}

关于如何在Android中格式化国际货币问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注创新互联行业资讯频道了解更多相关知识。


当前名称:如何在Android中格式化国际货币-创新互联
URL分享:http://scgulin.cn/article/hceic.html