我刚开始使用比特币,我做了一个javascript,每秒增加10个satoshi,然后它显示在BTC的屏幕上。
有人能告诉我为什么它开始显示奇怪的数字然后小数点不正确吗?我需要它从0.00000010 BTC开始
⚙ ~ exec fish
set: Invalid character “.” in variable name. Only alphanumerical characters and underscores are valid in a variable name.
/usr/local/share/fish/functions/setenv.fish (line 10): set -gx $v $$v
^
in function “setenv”
called on line 46 of file ~/.config/fish/config.fish
with parameter list “LANG en_US.UTF-8”
from sourcing file ~/.config/fish/config.fish
called during startup
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
~ echo $FISH_VERSION
2.5.0-238-ga811ae2
答案 0 :(得分:0)
使用toFixed()
可以得到结果: - )
var start = 0 ;
window.setInterval(function () {
start = start + 10;
var btc = parseFloat(start / 100000000).toFixed(8);
console.log(btc + " BTC");
}, 1000);
答案 1 :(得分:0)
toFixed()
方法可以解决这个问题,如果你想从它开始,你还必须使用0.00000010
增量。请参阅下面的工作代码:
var start = 0;
window.setInterval(
function() {
start = start + 0.00000010;
var btc = start.toFixed(8);
document.getElementById("start").innerHTML = btc + " BTC";
}, 1000);
<p id='start'></p>