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

Global configuration for currency formatting ('Currency != Number format') #6

Closed
lukebarton opened this issue Aug 23, 2011 · 5 comments
Assignees

Comments

@lukebarton
Copy link

Currency is not the same thing as number format and therefore I propose to you that they be treated seperately, hopefully using some sort of locale identifier.

Being from the UK, I prefer numbers in the following format: 123,456.78

Viewing a price in EUR € doesn't mean I would like the numbers displayed as 123.456,78

Zend Framework has an implementation you may find helpful to review:
http://framework.zend.com/manual/en/zend.locale.parsing.html#zend.locale.number.localize

@wjcrowcroft
Copy link
Member

Fair point - I'm from the UK as well, which is IMHO the only place in the world that does currency right.. I agree that a user shouldn't have to see EU-style formatting if they're used to standard formatting, or vice-versa..

Having said that, I think this is something that will be best handled by the parameters passed to the method (and in the next version, some form of configuration/settings object) - which leaves it squarely up to the developer. I'd say the job of the library is to provide a way of making that as easy as possible for them to present the correct number formatting for any given user.

It would definitely be an application-specific method of defining which locale to set, so I think this will be solved by the planned global settings configuration for the next version. Hope you can check it out when it's updated and let me know your thoughts!

Oh and thanks for the link, I'll take a look over it.

@ghost ghost assigned wjcrowcroft Aug 23, 2011
@lukebarton
Copy link
Author

Currency is just a unit, just like weight, pressure, temperature, distance or density. The value (number) is seperate from that.

I agree about the parameter, a quick google suggests there is little you can garner from the client itself. Perhaps a global configuration overridable by a parameter would be the best approach.

@wjcrowcroft
Copy link
Member

Yeah, good call. Working on that now.

@lukebarton
Copy link
Author

Damn comment & close button :)

@wjcrowcroft
Copy link
Member

Hey, I've just pushed v0.1.3 which adds a configurable settings object, which allows a developer to set the global localisation defaults under two objects, currency and number:

// Settings object that controls default parameters for library methods:
accounting.settings = {
    currency: {
        symbol : "$",   // default currency symbol is '$'
        format: "%s%v", // this controls string output: %s = symbol, %v = value/number
        decimal : ".",  // decimal point separator
        thousand: ",",  // thousands separator
        precision : 2   // decimal places
    },
    number: {
        precision : 0,  // default precision on numbers is 0
        thousand: ",",
        decimal : "."
    }
}

I'm leaving it up to individual developers and applications to decide which formatting to show the user, but I do have plans to build an optional plugin with default locale data for some common regions or countries... more on that later.

Until then I'd say this one's wrapped up, though there's more to do fo' sho'

Please re-open or make a new issue if you find bugs in the new code. Cheers!

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