fengari icon indicating copy to clipboard operation
fengari copied to clipboard

Wrong behavior of string.format

Open Egor-Skriptunoff opened this issue 6 years ago • 2 comments

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

Egor-Skriptunoff avatar Feb 12 '19 21:02 Egor-Skriptunoff

fengari uses the sprintf-js npm package for string formatting. Can you replicate the issue with that?

daurnimator avatar Feb 13 '19 04:02 daurnimator

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

daurnimator avatar Feb 13 '19 04:02 daurnimator