亚洲国产成人,色呦呦内射午夜,无码一级片,无码人妻少妇色欲AV一区二区

<samp id="jg8hh"></samp>

<p id="jg8hh"></p><delect id="jg8hh"><em id="jg8hh"><blockquote id="jg8hh"></blockquote></em></delect><acronym id="jg8hh"><dd id="jg8hh"></dd></acronym><button id="jg8hh"><dd id="jg8hh"><acronym id="jg8hh"></acronym></dd></button><samp id="jg8hh"><em id="jg8hh"><blockquote id="jg8hh"></blockquote></em></samp>

<p id="jg8hh"></p>

<samp id="jg8hh"><legend id="jg8hh"></legend></samp>
<samp id="jg8hh"><legend id="jg8hh"><samp id="jg8hh"></samp></legend></samp>

<samp id="jg8hh"></samp>

<p id="jg8hh"></p><acronym id="jg8hh"></acronym><p id="jg8hh"><dd id="jg8hh"><acronym id="jg8hh"></acronym></dd></p><p id="jg8hh"></p>

<p id="jg8hh"></p><delect id="jg8hh"><legend id="jg8hh"><var id="jg8hh"></var></legend></delect><button id="jg8hh"><listing id="jg8hh"><i id="jg8hh"></i></listing></button>
<delect id="jg8hh"><legend id="jg8hh"><var id="jg8hh"></var></legend></delect>

javascript 浮點(diǎn)數(shù)(js浮點(diǎn)計(jì)算精度問(wèn)題)

發(fā)布時(shí)間:2023-11-10
本文主要介紹javascript浮點(diǎn)數(shù)(js浮點(diǎn)計(jì)算精度問(wèn)題),下面一起看看javascript浮點(diǎn)數(shù)(js浮點(diǎn)計(jì)算精度問(wèn)題)相關(guān)資訊。
javascript中只有一種類型的數(shù)字,javascript中所有的數(shù)字都用ieee-754標(biāo)準(zhǔn)格式表示。浮點(diǎn)數(shù)的準(zhǔn)確性不是javascript獨(dú)有的,因?yàn)橛枚M(jìn)制表示的十進(jìn)制數(shù)是無(wú)限的。十進(jìn)制二進(jìn)制0.1 0.0001100110011001…0.2 0.001100111…0.3 0.01001101100…0.4 0.001101101110…0.5 0.6 0.100010.1000111011 javascript中的問(wèn)題比較復(fù)雜,這里只給出部分測(cè)試數(shù)據(jù):console.log(1really console . log(1.0-0.2 = = 0.8)//really console . log(1.0-0.1 = = 0.9)//really這個(gè)1.0-0.9怎么避免!= 0.1非bug問(wèn)題下面給出了一個(gè)更廣泛使用的解決方案。在判斷浮點(diǎn)運(yùn)算的結(jié)果之前,會(huì)降低計(jì)算的精度,因?yàn)樵诮档途鹊倪^(guò)程中總有四輪五項(xiàng)。(1.0-0.9)。tofixed (bit)//precision參數(shù)應(yīng)介于0和20之間。console . log(parse float((1.0-0.9))。fixed(10))= 0.1//true)console . log(parse float((1.0-0.8)。fixed(10))= 0.2//true)console . log(解析浮點(diǎn)((1.0-0.7)。tofixed(10))= 0.3//true)console . log(parse float((11.0-11.8))。fixed(10))= = = 0.8)//真的寫(xiě)個(gè)辦法:確定值的方法等于//(number1,number2函數(shù)相等,number){ number = number = undefined 10:number;默認(rèn)精度為10。返回number1.tofixed(數(shù)字)= number2.tofixed(數(shù)字);} console.log(等于(1.0-0.7,0.3));//真原型/擴(kuò)展模式,偏好面向?qū)ο箫L(fēng)格number . prototype . is equal = function(位數(shù)){ number = number = undefined 10:number;默認(rèn)精度為10。返回this . to fixed(digits)= number . to fixed(numbers);} console.log((1.0-0.7).is equal(0.3));//真的接下來(lái),試試浮點(diǎn)運(yùn)算。console . log(1.79 0.12)//1.91000000000000001 console . log(2.01-0.12)//1.88999999999999997 console . log(1.01×1.3)//1.3130000000000002 console . log(0.69/10)//0.0689999999999999說(shuō)明:javascript加法結(jié)果會(huì)有誤差,兩者浮動(dòng)在一起會(huì)更明顯。這個(gè)函數(shù)返回一個(gè)更精確的加法結(jié)果。//tel: accadd(arg1,arg2)//返回值:arg1加arg 2精確結(jié)果函數(shù)accadd(arg1,arg2){ var,r2,m;試試{r1 = arg1.tostring(split)。{){ 1}}長(zhǎng)度捕獲(e){ = 0 } try { r2 = arg 2 . tostring(split。{){ 1 } } length capture(e){ = 0 } m = math . pow(10,math.max(r1,r2))返回(arg1 * m 2×m)/ m}增加加號(hào)類型的方法,調(diào)用起來(lái)更方便。number . prototype . add = function(arg){ return accadd(arg,this);}減能,減法得到準(zhǔn)確結(jié)果:javascript加法的結(jié)果會(huì)有誤差,兩者浮動(dòng)在一起會(huì)更明顯。這個(gè)函數(shù)返回一個(gè)更精確的減法結(jié)果。//tel: accsub(arg1,arg 2)//返回值:arg1減2精確結(jié)果函數(shù)accsub(arg1,arg2){ var,r2,m,n;試試{r1 = arg1.tostring(split)。{){ 1}}長(zhǎng)度捕獲(e){ = 0 } try { r2 = arg 2 . tostring(split。{){ 1}}長(zhǎng)度捕獲(e){ = 0} m = math.pow(10,math.max(r1,r2)););//最后修改的deeka動(dòng)態(tài)控制精度長(zhǎng)度n(= r2 = r2);returns((arg 1 * m-arg 2×m)/m)fixed(n);}得到一個(gè)準(zhǔn)確的除法/函數(shù)除法結(jié)果。描述:javascript/除法結(jié)果會(huì)出錯(cuò)。當(dāng)兩個(gè)浮點(diǎn)除法比較明顯的時(shí)候,這個(gè)函數(shù)會(huì)返回一個(gè)比較準(zhǔn)確的除法結(jié)果。//tel: accdiv(arg1,arg 2)//返回值:精確結(jié)果除以2 arg1函數(shù)accdiv(arg1,arg2){ var t1 = 0,t2 = 0,r1,r2;嘗試{t1 = arg1.tostring(。分)(。){ 1 }。length}追到(e){}試試{t2 = arg2.tostring(。分)(。){ 1 }。長(zhǎng)度}趕上(e){}使用(數(shù)學(xué)){r1 =數(shù)字(arg1.tostring。替換(,r2 = number (arg2.tostring)。替換(,返回(r1和r2)* pow(10,t2-t1);}}增加div類型數(shù)量的方法,調(diào)用更方便。number . prototype . div = function(arg){ returns accdiv(this,arg);}熟悉乘法函數(shù),乘法準(zhǔn)確描述:當(dāng)兩個(gè)浮點(diǎn)乘法比較明顯時(shí),會(huì)出現(xiàn)錯(cuò)誤,這個(gè)函數(shù)會(huì)返回比較準(zhǔn)確的乘法結(jié)果。//tel: accmul(arg1,arg 2)//返回值:arg1乘以2精確結(jié)果函數(shù)accmul(arg1,arg2){ var m = 0,s1,s2 = = arg 1 . tostringarg 2 . tostring;請(qǐng)嘗試{m = s1.split(,){1}。length}追到(e){}試試{m = s2.split(,){1}。長(zhǎng)的度}趕上(e){}號(hào)(s1.replace(。}一種改進(jìn)多/數(shù)字類型的方法,調(diào)用起來(lái)更方便。number . prototype . mul = function(arg){ returns accmul(arg,this);} check: console.log(accadd(1.79,0.12));/ / 1.91 console.log(accsub(2.01,0.12));/ / 1.89 console.log(accdiv(0.69,10));/ / 0.069console.log(accmul(1.01,1.3));//1.313改造后可以愉快地操作運(yùn)算的內(nèi)容~加減乘除。希望對(duì)大家有幫助,支持你。
了解更多javascript浮點(diǎn)數(shù)(js浮點(diǎn)計(jì)算精度問(wèn)題)相關(guān)內(nèi)容請(qǐng)關(guān)注本站點(diǎn)。
上一個(gè):美好生活質(zhì)素的瞬間定格--《偶爾,茶樹(shù)》品讀
下一個(gè):信息化時(shí)代下的電子元器件出路

usb無(wú)法識(shí)別修復(fù)工具解決方法(usb無(wú)法識(shí)別修復(fù)工具解決方法怎么辦)
深圳特種車輛限行嗎(深圳特種車輛)
微信小程序無(wú)法打開(kāi)該頁(yè)面(微信小程序無(wú)法打開(kāi)攝像頭)
微軟收購(gòu)了哪些游戲(微軟收購(gòu)epic)
西湖龍井的歷史淵源
德國(guó)力士樂(lè)rexroth帶電磁啟動(dòng)的方向座閥e
122M 50V X7R 0201電容型號(hào)推薦
運(yùn)行中的電容器的維護(hù)和保養(yǎng)內(nèi)容?
餓了么5元無(wú)限制紅包是真的嗎(餓了么5元無(wú)限制紅包怎么設(shè)置)
比較全面的放線放樣技巧問(wèn)答