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

float specifier maxes out at 20. #149

Open
daurnimator opened this issue Jun 18, 2017 · 6 comments
Open

float specifier maxes out at 20. #149

daurnimator opened this issue Jun 18, 2017 · 6 comments
Labels

Comments

@daurnimator
Copy link
Contributor

e.g.

> require("sprintf").sprintf("%.99f", 1)
RangeError: toFixed() digits argument must be between 0 and 20
    at Number.toFixed (<anonymous>)
    at str_format.format (./node_modules/sprintf/lib/sprintf.js:170:49)
@alexei
Copy link
Owner

alexei commented Jun 18, 2017

Yes

@alexei alexei added the invalid label Jun 18, 2017
@alexei alexei closed this as completed Jun 18, 2017
@daurnimator
Copy link
Contributor Author

Even in C89 sprintf has no such limitation (well it did have max 99).
If you don't want to implement it, then it at least needs a warning in the docs.

@alexei
Copy link
Owner

alexei commented Jun 18, 2017

This is a JS implementation and works inside JS limits so I don't think this is warranted.

As a side note, if one's using JavaScript and is bloody serious about the number of digits after the decimal point and finds that 20 digits are insufficient, they're probably using some decimal type. Since this particular implementation has no support for custom types or custom formatting methods, they're probably not using this library either. That, or they print it out as a string and be done with it.

@alexei
Copy link
Owner

alexei commented Jun 18, 2017

Otoh what might work would be to do away with the type casting. Then one might be able to implement their own toFixed, toPrecision etc. methods on their own special "types".

That would also mean users would have to pass arguments with the appropriate types (i.e. pass float when they mean float etc)

Even though the chance of having someone complain the next day about me breaking their app is pretty high, that's that change (dropping type casting) is something I'd think about and probably agree with 😊

Opinions?

@alexei alexei reopened this Jun 18, 2017
@alexei
Copy link
Owner

alexei commented Jun 18, 2017

I updated my previous comment to make it clear that I'd probably agree with forcing users to pass arguments with the appropriate type.

@daurnimator
Copy link
Contributor Author

The issue I have is that I'm sharing sprintf strings between a C and a JS codebase: %.99f works in C, but not in JS.

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

No branches or pull requests

2 participants