Trailing zero 尾隨零,是與 Leading zero 前導零 完全相反的概念,是在數字後面補0,詳細可以看維基百科的解說,具體用法如下
直觀的對比就如下:
一般數字 | 經過 Trailing zero 處理 |
---|---|
123 | 123000000 |
44444 | 444440000 |
5566666 | 556666600 |
7890 | 789000000 |
9876543 | 987654300 |
JS 數字後面補0
Trailing zero的概念是沒有滿足長度時,往後面補0,可以直接照下面這樣做。
// 數字、字串後補0
// code : 你輸入的資料(字串、數字)
// dataLength : 資料補0後的長度
function TrailingZero( code, dataLength){
var str = code + Array(10).join('0');
return str.slice(0 , dataLength)
}
var str = 'abc123'
console.log(TrailingZero(str , 10))
// output : 'abc1230000'
同樣,你可以在後面加上任何你想加的符號,直接把 join()中的0,改成你希望補的代號就可以了。
相容 IE 老系統
如果你是串接很老的系統,比方說對方還是使用 IE 開啟,可以更換為以下代碼:
// input: (123 , 8) , output : 12300000
function TrailingZero( code, dataLength){
var str = code + '0000000000';
return str.slice(0 , dataLength);
}
var str = 'abc123'
console.log(TrailingZero(str , 10))
// output : 'abc1230000'
Binance
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
binance open account
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
create a binance account
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
米糕
What is the problem?
binance bonus za prijavo
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me. https://accounts.binance.com/sl/register-person?ref=DB40ITMB
Kayıt Ol | Gate.io
After reading your article, I have some doubts about gate.io. I don’t know if you’re free? I would like to consult with you. thank you.
binance Sign Up
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
رمز الإحالة لـ binance
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
gate.io kimlik doğrulama süresi
I am a student of BAK College. The recent paper competition gave me a lot of headaches, and I checked a lot of information. Finally, after reading your article, it suddenly dawned on me that I can still have such an idea. grateful. But I still have some questions, hope you can help me.
gateio
The point of view of your article has taught me a lot, and I already know how to improve the paper on gate.oi, thank you. https://www.gate.io/de/signup/XwNAU