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

Add support for custom number formatting #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

patkec
Copy link

@patkec patkec commented May 9, 2017

Added support for custom number formatting. This way one can override the default formatting to support localization.
Since localization usually depends on the environment (e.g. using Angular) the actual localization can as well be externalized.

Should help with #124.

@alexei
Copy link
Owner

alexei commented May 10, 2017

Like I said in the PR you linked, I wouldn't do it without Intl or something similar

@patkec
Copy link
Author

patkec commented May 10, 2017

Rolling your own Intl seems a bit of an overkill, but fair enough. I'll use my modification for the time being and keep an eye on the #124 issue.
But all in all, kudos for the lib, it's a great lib!

@alexei
Copy link
Owner

alexei commented May 10, 2017

I only suggested we shouldn't improvise

@alexei
Copy link
Owner

alexei commented May 10, 2017

Btw, my guess you're in need to format monetary values. If that's the case, may I suggest using a library that does just that? accounting.js looks good

@patkec
Copy link
Author

patkec commented May 10, 2017

My use case is actually formatting numbers (not monetary) in an Angular application where we are using different locales depending on user settings. And there it's as easy as just using $filter('number')(value). That is why I thought that sprintf-js could just offer a simple extensibility point and then it's up to lib users what they do with it.

@alexei
Copy link
Owner

alexei commented May 10, 2017

Btw, are you using the sprintf filter in Angular? Just asking.

Re extensibility: I totally understand what you're saying. Though I'm not that happy with the implementation of this lib (made some bad decisions in my youth 😀), it pretty much does what it's supposed to do and so I'm satisfied. Also the npm stats are positive. However, about a month ago I started thinking that it might be the time to move on and surpass sprintf. I've been pondering with the idea of implementing a different formatter that's similar in style and concept to Python's new style string formatter where you have more control over the formatting of any type whether built in or not. I haven't got the chance to write a prototype though 🙁 I can't promise anything, but I do hope I'll do it. Having said that, I don't see sprintf getting any of that candy.

@patkec
Copy link
Author

patkec commented May 10, 2017

Yes, I'm using the sprintf filter, with the addition of the number formatting that I mentioned.

Idea about a shiny new lib is definitely interesting! But yeah, adding some extensive features to sprintf is probably not feasible, I totally understand that.

@theophilusx
Copy link

Just wondering where this has got to. I also have a need to format large numbers (not currency) and it would be handy to have this in sprintf

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

Successfully merging this pull request may close these issues.

3 participants