Skip to content

Commit

Permalink
fixing issue when calculating decimal point progress values
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-c-woodard committed Nov 26, 2024
1 parent d86ee39 commit ffa4a18
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion includes/assets/js/kb-progress-bars.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions src/assets/js/kb-progress-bars.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,25 @@
const elementAbove = element.querySelector('.kb-current-progress-above');
const elementInside = element.querySelector('.kb-current-progress-inside');
const elementBelow = element.querySelector('.kb-current-progress-below');

//get current raw progress value
if (item.is_relative) {
value = Math.round(bar.value() * 100);
value = bar.value() * 100;
} else {
value = Math.round(bar.value() * item.progress_max);
value = bar.value() * item.progress_max;
}

//format the value according to decimal points indicated in settings
if (item.decimal === 'one') {
value = Math.round(bar.value() * 10) / 10;
value = Math.round(value * 10) / 10;
value = value.toFixed(1);
} else if (item.decimal === 'two') {
value = Math.round(bar.value() * 100) / 100;
value = Math.round(value * 100) / 100;
value = value.toFixed(2);
} else {
value = Math.round(value);
}

if (elementAbove) {
elementAbove.innerHTML = prefix + value + suffix;
} else if (elementInside) {
Expand Down

0 comments on commit ffa4a18

Please sign in to comment.