toLocaleString(locale, options)

    • local String,用于指定本地环境中存在的语言系统
    • options Objec,附加选项,用来指定字符串的显示格式
    1. // 数字分割 123,456.123
    2. const numOne = 123456.123;
    3. numOne.toLocaleString()
    4. // 数字转为百分比 12%
    5. const numTwo = 0.12;
    6. numTwo.toLocaleString('zh', { style: 'percent' ));
    7. // 数字转为货币表示法 ¥1,000,000.00
    8. const numThree = 1000000;
    9. numThree.toLocaleString('zh', { style: 'currency', currency: 'cny' });
    10. // CNY 1,000,000.00
    11. numThree.toLocaleString('zh', { style: 'currency', currency: 'cny', currencyDisplay: 'code' });
    12. // 1,000,000.00人民币
    13. numThree.toLocaleString('zh', { style: 'currency', currency: 'cny', currencyDisplay: 'name' });