如何通過貨幣符號"CURRENCY" 擷取對應的 LOCALE 資訊。

來源:互聯網
上載者:User
出現此問題的原因如下:

有國際儲值業務,資訊如下:

MONEY:₱48.00 CURRENCY:PHP

其中money 為儲值金額(當前locale的金額), currency為貨幣資訊與 money對應。

為了統計記賬方便均想把money ₱48.00 轉換成為肉眼可是識別的浮點數資訊。

於是藉助PHP官方intl擴充進行如下代碼開發:

$locale = ?$money  = '₱48.00';$currency = 'PHP';$fmt    = new NumberFormatter($locale, NumberFormatter::CURRENCY);$__     = $fmt->parseCurrency($money, $currency);var_dump($__)//$__ === false為轉換失敗,若為float 則轉換成功

不料卻遇見locale資訊無法擷取的困難,再藉助intllocale來擷取如下:

$locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);var_dump($locale);

但是accept_language不是正常的locale資訊

所以是否有辦法通過 currency 擷取到 locale

回複內容:

出現此問題的原因如下:

有國際儲值業務,資訊如下:

MONEY:₱48.00 CURRENCY:PHP

其中money 為儲值金額(當前locale的金額), currency為貨幣資訊與 money對應。

為了統計記賬方便均想把money ₱48.00 轉換成為肉眼可是識別的浮點數資訊。

於是藉助PHP官方intl擴充進行如下代碼開發:

$locale = ?$money  = '₱48.00';$currency = 'PHP';$fmt    = new NumberFormatter($locale, NumberFormatter::CURRENCY);$__     = $fmt->parseCurrency($money, $currency);var_dump($__)//$__ === false為轉換失敗,若為float 則轉換成功

不料卻遇見locale資訊無法擷取的困難,再藉助intllocale來擷取如下:

$locale = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);var_dump($locale);

但是accept_language不是正常的locale資訊

所以是否有辦法通過 currency 擷取到 locale

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.