Merge pull request #284 from mikebryant/make-small-numbers-more-readable

fix: Decrease precision for tiny numbers
master
Mike Bryant 5 years ago committed by GitHub
commit ad1ad300e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -259,6 +259,21 @@ const getPriceClass = function(buy_price, max) {
return "";
}
const displayPercentage = function(fraction) {
if (Number.isFinite(fraction)) {
let percent = fraction * 100;
if (percent >= 1) {
return percent.toPrecision(3) + '%';
} else if (percent >= 0.01) {
return percent.toFixed(2) + '%';
} else {
return '<0.01%';
}
} else {
return '—'
}
}
const calculateOutput = function (data, first_buy, previous_pattern) {
if (isEmpty(data)) {
$("#output").html("");
@ -276,10 +291,9 @@ const calculateOutput = function (data, first_buy, previous_pattern) {
pattern_count = analyzed_possibilities
.filter(val => val.pattern_number == poss.pattern_number)
.length
percentage_display = percent => Number.isFinite(percent) ? ((percent * 100).toPrecision(3) + '%') : '—'
out_line += `<td rowspan=${pattern_count}>${percentage_display(poss.category_total_probability)}</td>`;
out_line += `<td rowspan=${pattern_count}>${displayPercentage(poss.category_total_probability)}</td>`;
}
out_line += `<td>${percentage_display(poss.probability)}</td>`;
out_line += `<td>${displayPercentage(poss.probability)}</td>`;
for (let day of poss.prices.slice(1)) {
let price_class = getPriceClass(buy_price, day.max);
if (day.min !== day.max) {

Loading…
Cancel
Save