亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Number.prototype.toLocaleString 的兼容問題

Number.prototype.toLocaleString 的兼容問題

慕工程0101907 2018-09-23 16:18:53
在做金額格式化的時候用到了 Number.prototype.toLocaleString 這個方法,但是在一些老版本的瀏覽器中會出現兼容問題var a = 10000000;a.toLocaleString();搜狗 7.5.5 多了 .000原來的格式化函數(格式化千分位且保留兩位小數)formatAmount: function (amount) {   if (typeof amount === 'undefined' || amount === '') return '';  if (amount - 0 === 0) return '0.00';  let num = amount - 0;  let str = (num-0).toFixed(2); // 保留兩位小數   let num_int = str.split('.')[0];  let num_point = str.split('.')[1];  return `${(num_int-0).toLocaleString()}.${num_point}`; }兼容后formatAmount: function (amount) { // 金額千位格式化       if (typeof amount === 'undefined' || amount === '') return '';      if (amount - 0 === 0) return '0.00';      let num = amount - 0;      let str = (num-0).toFixed(2); // 保留兩位小時       let num_int = (str.split('.')[0] - 0).toLocaleString();      let num_point = str.split('.')[1];      return `${num_int.indexOf('.')>-1?num_int.split('.')[0]:num_int}.${num_point}`;     }搜狗 7.5.5 的內核版本是 Chromium 49.0.2623根據MDN顯示是支持這個方法的。那這種兼容性該怎么判斷?方法可以用但是返回的結果不同。
查看完整描述

1 回答

?
楊魅力

TA貢獻1811條經驗 獲得超6個贊

.toLocaleString(undefined,{minimumFractionDigits:0,maximumFractionDigits:0})


查看完整回答
反對 回復 2018-09-23
  • 1 回答
  • 0 關注
  • 731 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號