You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为Google Play内购的不同美元货币添加对应币种标识?

解决Google Play内购价格区分不同美元币种的问题

默认的getFormattedPrice()方法只能返回带货币符号的价格,像加拿大、澳大利亚、新西兰这类和美国共用$符号的地区,就没法直接区分对应的币种。要生成带CAD、AUD这类标识的价格,你可以这么做:

  • 从OneTimePurchaseOfferDetails中获取ISO 4217标准的三位货币代码,调用getCurrencyCode()方法就能拿到,比如美国返回USD、加拿大返回CAD、澳大利亚返回AUD。
  • 把格式化后的价格和货币代码拼接,按需调整显示格式。

示例代码如下:

ProductDetails.OneTimePurchaseOfferDetails oneTimePurchaseOfferDetails = productDetails.getOneTimePurchaseOfferDetails();
if (oneTimePurchaseOfferDetails != null) {
    String formattedPrice = oneTimePurchaseOfferDetails.getFormattedPrice();
    String currencyCode = oneTimePurchaseOfferDetails.getCurrencyCode();
    // 按需选择格式,比如 "$4.99 CAD" 或者 "CAD $4.99"
    String priceWithCurrency = formattedPrice + " " + currencyCode;
}

你可以根据产品的UI需求调整拼接方式,比如把币种放在价格前面,或者用括号包裹,比如"(" + currencyCode + ") " + formattedPrice,这样用户就能清晰区分不同地区的美元价格了。

内容的提问来源于stack exchange,提问作者Flyview

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 00:17:05