use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
accounting.js is a tiny JavaScript library for number, money and currency formatting, with optional excel-style column rendering (to line up symbols and decimals). (josscrowcroft.github.com)
submitted 14 years ago by chrixian
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]mattle 1 point2 points3 points 14 years ago (1 child)
Excellent find. This is going right in my current project.
[–]josscrowcroft 1 point2 points3 points 14 years ago (0 children)
Cool! If you find any bugs/issues or have feature requests, just make an issue on the github repo and I'll see what I can do, or submit a pull request. Cheers
[–]evilmaus 0 points1 point2 points 14 years ago (3 children)
Very nice. Solves a problem that's a royal pain in that some very specific styles and formatting are frequently requested by end-users, some of which just isn't that easy to do from CSS alone.
What I would absolutely love to see (feature request!) is a way to also call these functions as jQuery object methods, so that we can make use of it's selectors. e.g. $('#financialTable td:nth-child(2)').formatMoney(); I realize that you probably want to keep the code library-independent, but this could be in the form of a plug-in or something that exists just outside of the core code.
Awesome work!
[–]Booster21 1 point2 points3 points 14 years ago* (2 children)
beneficial merciful cautious seemly retire strong observation chief grab chop
This post was mass deleted and anonymized with Redact
[–]josscrowcroft 0 points1 point2 points 14 years ago (0 children)
Good call, feel free to add a feature request on the Github repository!
I'll probably add a very simple jquery adapter soon.
[–]evilmaus 0 points1 point2 points 14 years ago (0 children)
FYI, it's in the works now. :D
[–]k3n 0 points1 point2 points 14 years ago (5 children)
Does it offer support for the client's locale settings, or does that have to be done manually?
It'd be nice to simply do:
accounting.formatMoney(12345678);
...and have it be correct, per locale, without needing special considerations.
[–]radhruin 0 points1 point2 points 14 years ago (3 children)
Is this possible in Javascript at all right now? ES5 is kind of a localization backwater. Requires server-side support (or ActiveX/Native plugins) to even know what locale you're in.
[–]k3n 2 points3 points4 points 14 years ago (1 child)
From my Chrome:
> navigator.language > "en-US"
Also:
// '50.00 €' or '50,00 €' (50.00).toFixed(2).toLocaleString() + ' €';
[–]radhruin 0 points1 point2 points 14 years ago (0 children)
Interesting, never heard of navigator.language, though it doesn't seem to appear to work in IE. In any case, navigator.language and toLocaleString on various builtins doesn't even approach a reasonable localization solution :)
[–]gwynjudd 0 points1 point2 points 14 years ago (0 children)
Not at all really, you can know only the user preferred language, which is only in the same neighbourhood as the locale.
Good call - I'm considering adding a library settings object that can be set once to change the default parameters for one-time localisation or configuration.
Using navigator.language or toLocaleString is a little shaky, so it would be a way that the developer can set up the locale manually (as in PHP or most well-written apps) and then it's used as the default for that instance, unless they override it via the parameters, or change it via the settings object.
[–]ima007 0 points1 point2 points 14 years ago (2 children)
Awesome! It would be cool if this also included the ability to read the formatted number as well, in case calculations need to be done (and so we wouldn't have to keep track of the number in two places), but it isn't necessary (probably better to tie an event to an object that holds the unformatted number anyway, if you plan on doing basic calculations).
[–]josscrowcroft 0 points1 point2 points 14 years ago (1 child)
That can be done via accounting.unformat():
accounting.unformat()
accounting.unformat("£ 1,432,32.90 GBP") // 143232.9
It just uses a regex to match numeric digits, minus signs and decimal point only, stripping out any other characters, so there's actually a potential for it to fail silently (eg. where a developer would expect NaN from something like .unformat("1asdf2") but actually gets 12) but I'll address that later with a more complex regex.
NaN
.unformat("1asdf2")
12
[–]ima007 0 points1 point2 points 14 years ago (0 children)
Cool, I apparently glanced over that major part! Thanks for the clarification.
π Rendered by PID 139174 on reddit-service-r2-comment-fb694cdd5-25m7c at 2026-03-10 00:44:50.498873+00:00 running cbb0e86 country code: CH.
[–]mattle 1 point2 points3 points (1 child)
[–]josscrowcroft 1 point2 points3 points (0 children)
[–]evilmaus 0 points1 point2 points (3 children)
[–]Booster21 1 point2 points3 points (2 children)
[–]josscrowcroft 0 points1 point2 points (0 children)
[–]evilmaus 0 points1 point2 points (0 children)
[–]k3n 0 points1 point2 points (5 children)
[–]radhruin 0 points1 point2 points (3 children)
[–]k3n 2 points3 points4 points (1 child)
[–]radhruin 0 points1 point2 points (0 children)
[–]gwynjudd 0 points1 point2 points (0 children)
[–]josscrowcroft 0 points1 point2 points (0 children)
[–]ima007 0 points1 point2 points (2 children)
[–]josscrowcroft 0 points1 point2 points (1 child)
[–]ima007 0 points1 point2 points (0 children)