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

currency parser: thousands separator support #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mbezhanov
Copy link

When working with large figures in accounting applications, it's often preferred to format your numbers with grouped thousands through thousands separators. In example, presenting a large figure like $1386915 as $1,386,915 instead, makes it much more readable to the end-user.

Most server-side scripting languages and spreadsheet applications provide all the necessary functionality for the purpose, in example:

http://php.net/manual/en/function.number-format.php
http://office.microsoft.com/en-001/excel-help/format-numbers-as-currency-HA102749029.aspx

...so many people rely on these functions in their everyday work to format and present their figures properly.

Unfortunately, Tablesorter doesn't provide native support to figures utilizing the aforementioned format, so if a user decides to present financial information formatted with thousands separators, Tablesorter identifies the data type as "currency", but is unable to sort it properly.

Therefore, I went ahead and added some minor modifications, so the currency parser can successfully sort figures, which make a use of thousands separators.

I have already used this functionality in a couple of projects and it works great. I hope it's useful to the community too.

All best,
Marin

@Mottie Mottie mentioned this pull request Oct 21, 2014
@mbezhanov
Copy link
Author

I have also added thousands separator support for the "digits" parser with the latest commit.

And here is an online demo: http://mbezhanov.github.io/tablesorter/example-thousands-separator.html

After reading #26 though, I'm not sure how much of a good idea that is...

@Mottie
Copy link
Collaborator

Mottie commented Oct 22, 2014

In my fork of tablesorter, I tackled this problem by adding a usNumberFormat option.

When that option is true, the formatFloat function removes commas. If false, it removes spaces and decimal points (code reference). This method seems to cover most of the currency formats I found.


Edit: Hmm, I guess it doesn't cover French Swiss formatting:

French - Swiss (4108): fr. 1'234.56 ‏

but in the currency parser, I do replace all non-digit characters as well:

$.tablesorter.formatFloat((s || '').replace(/[^\w,. \-()]/g, ""), table);

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.

2 participants