fengari
fengari copied to clipboard
Wrong behavior of string.format
C language docs says the following about .precision field in sprintf() format:
If the period is specified without an explicit value for precision, 0 is assumed.
But Fengari raises error instead of assuming zero:
> print(("%.0f"):format(42.5))
43
> print(("%.f"):format(42.5))
SyntaxError: [sprintf] unexpected placeholder
fengari uses the sprintf-js npm package for string formatting. Can you replicate the issue with that?
Can you replicate the issue with that?
Yep:
$ node
> require("sprintf-js").sprintf("%.f", 2)
Thrown:
SyntaxError: [sprintf] unexpected placeholder
> require("sprintf-js").sprintf("%.0f", 2)
'2'
Filed https://github.com/alexei/sprintf.js/issues/181