尝试从右侧添加字符串,从右侧移到特定区域
我一直在尝试弄清楚如何在某个地方添加一个字符串,这是代码
function fixBalance(amount){
if(amount <= 99999999){
var amt = "0." + amount.toString().padStart(8, "0");
return Number(amt);
} else {
return false;
}
}
console.log(fixBalance(1));
console.log(fixBalance(1000));
console.log(fixBalance(10000000));
console.log(fixBalance(1000000000));
基本上,通过8个数字后,有8个空间在0的右侧
,我希望数字不断超过该期间
:
1 = 0.00000001
1000 = 0.00001000或0.00001
10000000 = 0.10000000 or 0.1
100001000 = 0.100001000
1000000001 = 10.00000001
1010000000 = 10.10000000
10100000000 = 101.00000000
如果我要放入1000000000,则应是10.00000000或10作为数值数字,
试图弄清楚如何使用其他语句来做这件事,
谢谢!
I've been trying to figure out how to add period as a string in a certain place, here's the code
function fixBalance(amount){
if(amount <= 99999999){
var amt = "0." + amount.toString().padStart(8, "0");
return Number(amt);
} else {
return false;
}
}
console.log(fixBalance(1));
console.log(fixBalance(1000));
console.log(fixBalance(10000000));
console.log(fixBalance(1000000000));
Basically, there are 8 spaces to the right of the 0
After it passes 8 numbers, I want numbers to keep going past the period
For example:
1 = 0.00000001
1000 = 0.00001000 or 0.00001
10000000 = 0.10000000 or 0.1
100001000 = 0.100001000
1000000001 = 10.00000001
1010000000 = 10.10000000
10100000000 = 101.00000000
If I were to put in 1000000000, it should be 10.00000000 or 10 as a numerical number
Trying to figure out how to do that with the else statement
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在组成之前,如何单独确定整数和十进制部分?
How about determining the integer and decimal parts separately before composing them?