【问题标题】:How do I use ZF2 I18n currencyformatter to format bitcoin?如何使用 ZF2 I18n currencyformatter 格式化比特币?
【发布时间】:2014-11-01 03:00:58
【问题描述】:

比特币允许小数点后 8 位 (123.45678912)。

我如何使用 ZF2 I18n 货币格式化程序来格式化一个完整的 8 位小数位的比特币金额,而不是将其缩短到小数点后 2 位?

【问题讨论】:

    标签: php zend-framework2 currency bitcoin


    【解决方案1】:

    要是我多花几分钟做一点研究就好了:

    来自 ZF2 的文档http://framework.zend.com/manual/2.3/en/modules/zend.i18n.view.helpers.html

    我找到了以下链接:

    http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#details

    如果您向下滚动到十进制格式和有效数字部分,您会看到答案。我最终这样做是为了让我的代码代表 BTC:

    $cur = getCurrency();
    
    $this->plugin("currencyformat")->setCurrencyCode($cur);
    
    if($cur == "BTC"):
        $this->plugin("currencyformat")->setCurrencyPattern('@############### ¤');
    endif;
    

    “@”表示至少显示一个数字。 15 位“#”加上“@”表示最大有效位数为 16。“¤”将在数字末尾显示货币。

    对于 MySQL,我用来存储这些金额的列是 DECIMAL(16,8),所以这对我来说非常适合。

    如果您有更好的建议,请随时分享。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-05
      • 2014-03-31
      • 1970-01-01
      • 1970-01-01
      • 2012-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多