码迷,mamicode.com
首页 > 其他好文 > 详细

[React Intl] Format Numbers with Separators and Currency Symbols using react-intl FormattedNumber

时间:2017-07-28 20:51:51      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:with   ==   format   ant   ops   local   correct   att   enc   

Using a react-intl FormattedNumber component, we‘ll pass a Number and a few additional props in order to render the correct separator and currency symbols for different languages.

 

For example we have price data as such:

        "price": {
          "en-US": "16.19",
          "es-ES": "15.09",
          "fr-FR": "15.09"
        },

 

We can use FormattedNumber  to display the correct currency.

let locale = (navigator.languages && navigator.languages[0])
             || navigator.language
             || navigator.userLanguage
             || ‘en-US‘;

            <p>
              <FormattedNumber 
                style=‘currency‘
                currency={locale === ‘en-US‘ ? ‘USD‘: ‘EUR‘}
                currencyDisplay=‘symbol‘
                value={merchant.price[locale]} />
            </p>

 

[React Intl] Format Numbers with Separators and Currency Symbols using react-intl FormattedNumber

标签:with   ==   format   ant   ops   local   correct   att   enc   

原文地址:http://www.cnblogs.com/Answer1215/p/7252432.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!