第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何將千位分隔符添加到 JS 數(shù)字以進(jìn)行字符串輸出?

如何將千位分隔符添加到 JS 數(shù)字以進(jìn)行字符串輸出?

慕慕森 2021-11-18 09:40:09
我有一個(gè) API 調(diào)用,它返回venue_capacity一個(gè)足球隊(duì)的數(shù)字,沒(méi)有千位分隔符。我想將其打印為字符串和千位分隔符。我的想法是在我從 API 獲得數(shù)據(jù)后運(yùn)行該函數(shù)以相應(yīng)地操作變量venue_capacity。這是我當(dāng)前的嘗試返回沒(méi)有分隔符的數(shù)字:  $.ajax({    method: "GET",    async: "True",    dataType: "json",    url: "https://cors-anywhere.herokuapp.com/https://www.api-football.com/demo/api/v2/teams/team/" + team_id,    success: function(response) {      var team_info = response;      console.log(team_info);      team = team_info.api.teams[0].name;      founded = team_info.api.teams[0].founded;      venue_capacity = team_info.api.teams[0].venue_capacity;      function numberWithCommas(venue_capacity) {        return venue_capacity.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");      }      $("#selectedClub").html(team);      $("#founded").html(founded);      $("#venue_capacity").html(venue_capacity);    }
查看完整描述

2 回答

?
哆啦的時(shí)光機(jī)

TA貢獻(xiàn)1779條經(jīng)驗(yàn) 獲得超6個(gè)贊

您不必function在范圍內(nèi)聲明s $.ajax- 只需一次性執(zhí)行翻譯:

venue_capacity = team_info.api.teams[0].venue_capacity.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");



查看完整回答
反對(duì) 回復(fù) 2021-11-18
?
DIEA

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超3個(gè)贊

嘗試改用這個(gè)函數(shù):


function formatWithCommat(x){

  return x.toLocaleString('en-GB');

}

您可以在此處找到有關(guān)它的更多信息 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString


查看完整回答
反對(duì) 回復(fù) 2021-11-18
  • 2 回答
  • 0 關(guān)注
  • 162 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)