Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong behavior of string.format #147

Open
Egor-Skriptunoff opened this issue Feb 12, 2019 · 2 comments
Open

Wrong behavior of string.format #147

Egor-Skriptunoff opened this issue Feb 12, 2019 · 2 comments

Comments

@Egor-Skriptunoff
Copy link

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
@daurnimator
Copy link
Member

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

@daurnimator
Copy link
Member

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 alexei/sprintf.js#181

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants