external_script modifies numeric output
nkuttler opened this issue · comments
The external_script module converts numeric values to a numeric type. This removes the original formatting of the input and is undesired.
To reproduce create an external script and simply echo "0.123000", the output in the bar will be "0.123".
Can you use format = "{output:.6f}"
for consistency?
This would work for my specific case, yes. If you prefer this solution I can add some documentation, type conversion is still unexpected.
We convert it to number to permit conditional statements like format = "[\?if=output {output}]"
.
(Alt) Output more to make it a string i.e. echo "0.123000 dollars"
.
All this is just suggestions. If either one works for you too (i.e. you now have two different solutions), then I suppose we could avoid adding this new config if possible. Conditional statements, imho, is more useful than preserving trailing zeroes.
Also, python does this too.
$ python
Python 3.9.10 (main, Jan 13 2022, 23:32:03)
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> output = 0.123000
>>> output
0.123
EDIT: It's a matter of making it a string... versus... leave it auto as-is.
@nkuttler I'd rather add a comment yes since we want to preserve the formatter syntax and logic please
@ultrabug My patch does not change the current behavior since I didn't want to break anything. It just makes it possible to preserve the output of external scripts.
@ultrabug The latest version has convert_decimal_number, and a default of True should reflect the current behavior? I've just renamed the option to convert_decimal_number as only such numbers are converted (e.g. not octal or hex numbers). The test failure was due to an alphabetic order, that should be fixed now, the tests pass for me. If you'd prefer an option that defaults to false, e.g. preserve_decimal_number I can do that too.