Skip to content

Commit 2535e8b

Browse files
committed
convert numeric strings to numbers for output
1 parent 4deefaa commit 2535e8b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

classes/local/evaluator.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ public function substitute_variables_in_text(string $text, bool $skiplists = tru
163163
if ($skiplists && in_array($result->type, [token::LIST, token::SET])) {
164164
continue;
165165
}
166+
// If the result is a numeric string, we convert it back to a number, in order for
167+
// the standard PHP formatting to apply: numbers with an absolute value ≥ 1e14
168+
// or < 0.0001 would normally be printed in scientific notation.
169+
if ($result->type === token::STRING && is_numeric($result->value)) {
170+
$result->type = token::NUMBER;
171+
$result->value = floatval($result->value);
172+
}
166173
// If the result is a number, we try to localize it, unless the admin settings do not
167174
// allow the decimal comma.
168175
if ($result->type === token::NUMBER) {

0 commit comments

Comments
 (0)