Skip to content

Commit daab8cc

Browse files
author
Graham Butler
committed
add percentage/decimal calculations
1 parent 5939cc1 commit daab8cc

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/element.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,22 @@ const AuthorBaseElement = superClass => class extends superClass {
602602
}
603603
},
604604

605+
getPercentageDecimal: {
606+
value: (portion, whole, decimalPlaces = null) => {
607+
let decimal = portion / whole
608+
609+
if (decimal < 0) {
610+
return 0
611+
}
612+
613+
if (decimalPlaces !== null) {
614+
return decimal.toFixed(decimalPlaces)
615+
}
616+
617+
return decimal
618+
}
619+
},
620+
605621
/**
606622
* @method insertStyleRule
607623
* Inserts a new CSS rule-set into the component's shadow root style sheet.

0 commit comments

Comments
 (0)