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

Use Normal Negative Currency #1300

Open
jlind opened this issue Mar 4, 2015 · 1 comment
Open

Use Normal Negative Currency #1300

jlind opened this issue Mar 4, 2015 · 1 comment
Milestone

Comments

@jlind
Copy link

jlind commented Mar 4, 2015

The MooTools formatCurrency uses a non-standard negative/prefix combination.

expect((-2000).formatCurrency()).toEqual('$ -2,000.00');

In MooTools the currency prefix is in front of the negative prefix. So currency is formatted like $ -2,000.00 and $ (2,000.00)
The standard seems to be -$2,000.00 and ($2,000.00)

Swapping the prefix ordering means it probably would break everything else... so more custom logic just for Currency? Seems like overkill.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/9195794-use-normal-negative-currency?utm_campaign=plugin&utm_content=tracker%2F22069&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F22069&utm_medium=issues&utm_source=github).
@SergioCrisostomo SergioCrisostomo added this to the 1.6.0 milestone Mar 5, 2015
@boppy
Copy link
Contributor

boppy commented Feb 5, 2017

It seems to be a small step to make that happen. You can reformat, but the manually set pre- and suffixes are not exclusively assigned.

First things first:
Your $ (1337.42) idea is already possible. Just:

Locale.define('en-US', 'Number', {
	currency: {
		prefix: '$ ',
		negative: {
			prefix: '(',
			suffix: ')'
		}
	}
});

But it will get harder if -$ 1337.42 should be possible. But:

Locale.define('te-st').inherit('EU', 'Number');
Locale.define('te-st', 'Number',  {
	currency: {
		prefix: '€ ',
		suffix: '+',
		negative: {
			exclusive: true, // to be implemented ;)
			prefix: '-Eur ',
			suffix: '-'
		}
	}
});
Locale.use('te-st');

(-1337.42).formatCurrency();
// will output:
// € -Eur 1.337,42+-

So just change https://github.com/mootools/mootools-more/blob/master/Source/Types/Number.Format.js#L35 to:

if (negativeLocale[key] != null) options[key] = (negativeLocale.exclusive ? '' : getOption(key)) + negativeLocale[key];

The != null check is to unset a suffix set by the "root"-Number by providing ''.

With this fix, it will output -Eur 1.337,42- as expected.

See: https://jsfiddle.net/nc7fu62j/2/
It's only JS-line 22 chat has a change.

Review at https://github.com/boppy/mootools-more/tree/fix-currency-bug-1300
I will provide a PR w/ specs if you're okay with that...

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

No branches or pull requests

3 participants