Skip to content

Commit 7792908

Browse files
committed
units & currency fix
1 parent 96c4c4d commit 7792908

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

input-num.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ static observedAttributes = [
772772
if (id != UNITS)
773773
txt.innerHTML = this.#formatNumber(this[id]);
774774
else if (this.units)
775-
txt.innerHTML = `${this.#locale.currency ? "/" : ""}${this.units}`;
775+
txt.innerHTML = this.#getUnits();
776776
else
777777
txt.innerHTML = "";
778778

@@ -839,13 +839,12 @@ static observedAttributes = [
839839
// #getText() gets the appropriate text for the #input
840840
#getText(inFocus, appendUnits) {
841841
const n = this.#attrs[VALUE];
842-
let txt = inFocus ? n : this.#formatNumber(n);
843-
if (appendUnits && this.units) {
844-
if (this.#locale.currency)
845-
txt += "/"; // currency && units displays currency per unit
846-
txt += this.units;
847-
}
848-
return txt;
842+
return (inFocus ? n : this.#formatNumber(n))
843+
+ (appendUnits && this.units ? this.#getUnits() : "");
844+
}
845+
// #getUnits() gets the units text, currency && units displays currency per unit
846+
#getUnits() {
847+
return `${this.useLocale && this.#locale.currency ? "/" : ""}${this.units}`;
849848
}
850849
// #formatNumber() formats a number for display as text
851850
#formatNumber(n) {

0 commit comments

Comments
 (0)