Skip to content

Commit f85f1d6

Browse files
committed
Let DOLLARS and PERCENT optionally return strings
1 parent da18e97 commit f85f1d6

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/formula-functions.svelte.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,27 @@ const dollarFormat = Intl.NumberFormat("en-US", {
133133
style: "currency",
134134
currency: "USD",
135135
});
136-
functions.dollars = undefinedArgsToIdentity(function (d) {
137-
this.element = document.createTextNode(dollarFormat.format(d));
136+
functions.dollars = undefinedArgsToIdentity(function (d, return_str) {
137+
const str = dollarFormat.format(d);
138+
if (return_str) {
139+
return str;
140+
}
141+
this.element = document.createTextNode(str);
138142
return d;
139143
});
140144

141145
const percentFormat = new Intl.NumberFormat("en-US", {
142146
style: "percent",
143147
maximumFractionDigits: 4,
144148
});
145-
functions.percent = function (p) {
146-
this.element = document.createTextNode(percentFormat.format(p));
149+
functions.percent = undefinedArgsToIdentity(function (p, return_str) {
150+
const str = percentFormat.format(p);
151+
if (return_str) {
152+
return str;
153+
}
154+
this.element = document.createTextNode(str);
147155
return p;
148-
};
156+
});
149157

150158
functions.sparkbars = (...args) => {
151159
const lines = "▁▂▃▄▅▆▇█";

0 commit comments

Comments
 (0)