Format big numbers with spaces

This commit is contained in:
Boris Kubiak 2018-01-15 08:38:23 +01:00
parent 539a24e97c
commit 431a873239
2 changed files with 6 additions and 3 deletions

View file

@ -102,8 +102,8 @@
</div>
<div class="col-md-6">
<div class="panel statistics">
<div>Difficulty: <span class="output" v-text="difficulty">1</span></div>
<div>Generated: <span class="output" v-text="count + (count === 1 ? ' address' : ' addresses')">0 addresses</span></div>
<div>Difficulty: <span class="output" v-text="formatNum(difficulty)">1</span></div>
<div>Generated: <span class="output" v-text="formatNum(count) + (count === 1 ? ' address' : ' addresses')">0 addresses</span></div>
<div>50% probability: <span class="output" v-text="probability50">0 addresses</span></div>
<div>Speed: <span class="output" v-text="speed + ' addr/s'">0 addr/s</span></div>
<div>Status: <span class="output" v-text="status">Waiting</span></div>

View file

@ -49,7 +49,7 @@ new Vue({
return this.inputError ? 'N/A' : computeDifficulty(this.input.prefix, this.input.checksum);
},
probability50: function () {
return this.inputError ? 'N/A' : Math.floor(Math.log(0.5) / Math.log(1 - (1 / this.difficulty))) + ' addresses';
return this.inputError ? 'N/A' : this.formatNum(Math.floor(Math.log(0.5) / Math.log(1 - (1 / this.difficulty)))) + ' addresses';
},
probability: function () {
return Math.round(10000 * computeProbability(this.difficulty, this.count)) / 100;
@ -171,6 +171,9 @@ new Vue({
this.cores = cores;
this.threads = this.cores;
}
},
formatNum: function (num) {
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ' ');
}
},