Skip to content

Commit cd9750d

Browse files
authored
Merge pull request #484 from adamwdraper/develop
2.0.5
2 parents a7a2ded + f1ec504 commit cd9750d

27 files changed

+524
-66
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ See [the english unit tests](https://github.com/adamwdraper/Numeral-js/blob/mast
5656

5757
# Changelog
5858

59+
### 2.0.5
60+
61+
Bug fix: Multi letter currency symbols and spacing
62+
63+
Added: Formatting of numbers with leading zeros
64+
65+
New format: Basic Point
66+
67+
Option: Added `scalePercentBy100` (default: true) option to turn on/off scaling percentages
68+
5969
### 2.0.4
6070

6171
Bug fix: Incorrect abbreviations for values rounded up [#187](https://github.com/adamwdraper/Numeral-js/issues/187)

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "numeral",
33
"repo": "adamwdraper/Numeral-js",
4-
"version": "2.0.4",
4+
"version": "2.0.5",
55
"description": "Format and manipulate numbers.",
66
"keywords": [
77
"numeral",

component.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "numeral",
33
"repo": "adamwdraper/Numeral-js",
4-
"version": "2.0.4",
4+
"version": "2.0.5",
55
"description": "Format and manipulate numbers.",
66
"keywords": [
77
"numeral",

locales.js

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*! @preserve
22
* numeral.js
3-
* locales : 2.0.4
3+
* locales : 2.0.5
44
* license : MIT
55
* http://adamwdraper.github.com/Numeral-js/
66
*/
@@ -15,30 +15,6 @@
1515
}
1616
}(this, function (numeral) {
1717

18-
(function() {
19-
numeral.register('locale', 'be-nl', {
20-
delimiters: {
21-
thousands: ' ',
22-
decimal : ','
23-
},
24-
abbreviations: {
25-
thousand : 'k',
26-
million : ' mln',
27-
billion : ' mld',
28-
trillion : ' bln'
29-
},
30-
ordinal : function (number) {
31-
var remainder = number % 100;
32-
33-
return (number !== 0 && remainder <= 1 || remainder === 8 || remainder >= 20) ? 'ste' : 'de';
34-
},
35-
currency: {
36-
symbol: '€ '
37-
}
38-
});
39-
})();
40-
41-
4218
(function() {
4319
numeral.register('locale', 'bg', {
4420
delimiters: {
@@ -510,6 +486,30 @@
510486
})();
511487

512488

489+
(function() {
490+
numeral.register('locale', 'nl-be', {
491+
delimiters: {
492+
thousands: ' ',
493+
decimal : ','
494+
},
495+
abbreviations: {
496+
thousand : 'k',
497+
million : ' mln',
498+
billion : ' mld',
499+
trillion : ' bln'
500+
},
501+
ordinal : function (number) {
502+
var remainder = number % 100;
503+
504+
return (number !== 0 && remainder <= 1 || remainder === 8 || remainder >= 20) ? 'ste' : 'de';
505+
},
506+
currency: {
507+
symbol: '€ '
508+
}
509+
});
510+
})();
511+
512+
513513
(function() {
514514
numeral.register('locale', 'nl-nl', {
515515
delimiters: {
@@ -820,4 +820,27 @@
820820
})();
821821

822822

823+
(function() {
824+
825+
numeral.register('locale', 'vi', {
826+
delimiters: {
827+
thousands: '.',
828+
decimal: ','
829+
},
830+
abbreviations: {
831+
thousand: ' nghìn',
832+
million: ' triệu',
833+
billion: ' tỷ',
834+
trillion: ' nghìn tỷ'
835+
},
836+
ordinal: function () {
837+
return '.';
838+
},
839+
currency: {
840+
symbol: '₫'
841+
}
842+
});
843+
})();
844+
845+
823846
}));

locales/be-nl.js renamed to locales/nl-be.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// numeral.js locale configuration
2-
// locale : belgium-dutch (be-nl)
2+
// locale : dutch-belgium (nl-be)
33
// author : Dieter Luypaert : https://github.com/moeriki
4+
// corrected : Olivier Godefroy : https://github.com/godefroyo
45

56
(function (global, factory) {
67
if (typeof define === 'function' && define.amd) {
@@ -11,7 +12,7 @@
1112
factory(global.numeral);
1213
}
1314
}(this, function (numeral) {
14-
numeral.register('locale', 'be-nl', {
15+
numeral.register('locale', 'nl-be', {
1516
delimiters: {
1617
thousands: ' ',
1718
decimal : ','

locales/vi.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// numeral.js locale configuration
2+
// locale : vietnam (vi)
3+
// author : Harry Nguyen : https://github.com/thaihoa311
4+
5+
(function (global, factory) {
6+
if (typeof define === 'function' && define.amd) {
7+
define(['../numeral'], factory);
8+
} else if (typeof module === 'object' && module.exports) {
9+
factory(require('../numeral'));
10+
} else {
11+
factory(global.numeral);
12+
}
13+
}(this, function (numeral) {
14+
15+
numeral.register('locale', 'vi', {
16+
delimiters: {
17+
thousands: '.',
18+
decimal: ','
19+
},
20+
abbreviations: {
21+
thousand: ' nghìn',
22+
million: ' triệu',
23+
billion: ' tỷ',
24+
trillion: ' nghìn tỷ'
25+
},
26+
ordinal: function () {
27+
return '.';
28+
},
29+
currency: {
30+
symbol: '₫'
31+
}
32+
});
33+
}));

min/locales.min.js

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

min/locales/be-nl.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

min/locales/nl-be.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

min/locales/nl-nl.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

min/numeral.min.js

Lines changed: 9 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

numeral.js

Lines changed: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*! @preserve
22
* numeral.js
3-
* version : 2.0.4
3+
* version : 2.0.5
44
* author : Adam Draper
55
* license : MIT
66
* http://adamwdraper.github.com/Numeral-js/
@@ -21,20 +21,22 @@
2121

2222
var numeral,
2323
_,
24-
VERSION = '2.0.4',
24+
VERSION = '2.0.5',
2525
formats = {},
2626
locales = {},
2727
defaults = {
2828
currentLocale: 'en',
2929
zeroFormat: null,
3030
nullFormat: null,
31-
defaultFormat: '0,0'
31+
defaultFormat: '0,0',
32+
scalePercentBy100: true
3233
},
3334
options = {
3435
currentLocale: defaults.currentLocale,
3536
zeroFormat: defaults.zeroFormat,
3637
nullFormat: defaults.nullFormat,
37-
defaultFormat: defaults.defaultFormat
38+
defaultFormat: defaults.defaultFormat,
39+
scalePercentBy100: defaults.scalePercentBy100
3840
};
3941

4042

@@ -103,6 +105,7 @@
103105
var locale = locales[numeral.options.currentLocale],
104106
negP = false,
105107
optDec = false,
108+
leadingCount = 0,
106109
abbr = '',
107110
trillion = 1000000000000,
108111
billion = 1000000000,
@@ -178,6 +181,7 @@
178181
int = value.toString().split('.')[0];
179182
precision = format.split('.')[1];
180183
thousands = format.indexOf(',');
184+
leadingCount = (format.split('.')[0].split(',')[0].match(/0/g) || []).length;
181185

182186
if (precision) {
183187
if (numeral._.includes(precision, '[')) {
@@ -200,7 +204,7 @@
200204
decimal = '';
201205
}
202206
} else {
203-
int = numeral._.toFixed(value, null, roundingFunction);
207+
int = numeral._.toFixed(value, 0, roundingFunction);
204208
}
205209

206210
// check abbreviation again after rounding
@@ -227,6 +231,12 @@
227231
neg = true;
228232
}
229233

234+
if (int.length < leadingCount) {
235+
for (var i = leadingCount - int.length; i > 0; i--) {
236+
int = '0' + int;
237+
}
238+
}
239+
230240
if (thousands > -1) {
231241
int = int.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1' + locale.delimiters.thousands);
232242
}
@@ -384,9 +394,8 @@
384394

385395
power = Math.pow(10, boundedPrecision);
386396

387-
//roundingFunction = (roundingFunction !== undefined ? roundingFunction : Math.round);
388397
// Multiply up by precision, round accurately, then divide and use native toFixed():
389-
output = (roundingFunction(value * power) / power).toFixed(boundedPrecision);
398+
output = (roundingFunction(value + 'e+' + boundedPrecision) / power).toFixed(boundedPrecision);
390399

391400
if (optionals > maxDecimals - boundedPrecision) {
392401
optionalsRegExp = new RegExp('\\.?0{1,' + (optionals - (maxDecimals - boundedPrecision)) + '}$');
@@ -682,6 +691,42 @@
682691

683692

684693

694+
(function() {
695+
numeral.register('format', 'bps', {
696+
regexps: {
697+
format: /(BPS)/,
698+
unformat: /(BPS)/
699+
},
700+
format: function(value, format, roundingFunction) {
701+
var space = numeral._.includes(format, ' BPS') ? ' ' : '',
702+
output;
703+
704+
value = value * 10000;
705+
706+
// check for space before BPS
707+
format = format.replace(/\s?BPS/, '');
708+
709+
output = numeral._.numberToFormat(value, format, roundingFunction);
710+
711+
if (numeral._.includes(output, ')')) {
712+
output = output.split('');
713+
714+
output.splice(-1, 0, space + 'BPS');
715+
716+
output = output.join('');
717+
} else {
718+
output = output + space + 'BPS';
719+
}
720+
721+
return output;
722+
},
723+
unformat: function(string) {
724+
return +(numeral._.stringToNumber(string) * 0.0001).toFixed(15);
725+
}
726+
});
727+
})();
728+
729+
685730
(function() {
686731
var decimal = {
687732
base: 1000,
@@ -692,10 +737,17 @@
692737
suffixes: ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']
693738
};
694739

740+
var allSuffixes = decimal.suffixes.concat(binary.suffixes.filter(function (item) {
741+
return decimal.suffixes.indexOf(item) < 0;
742+
}));
743+
var unformatRegex = allSuffixes.join('|');
744+
// Allow support for BPS (http://www.investopedia.com/terms/b/basispoint.asp)
745+
unformatRegex = '(' + unformatRegex.replace('B', 'B(?!PS)') + ')';
746+
695747
numeral.register('format', 'bytes', {
696748
regexps: {
697749
format: /([0\s]i?b)/,
698-
unformat: new RegExp('(' + decimal.suffixes.concat(binary.suffixes).join('|') + ')')
750+
unformat: new RegExp(unformatRegex)
699751
},
700752
format: function(value, format, roundingFunction) {
701753
var output,
@@ -794,7 +846,7 @@
794846
output = numeral._.insert(output, locale.currency.symbol, i);
795847
break;
796848
case ' ':
797-
output = numeral._.insert(output, ' ', i);
849+
output = numeral._.insert(output, ' ', i + locale.currency.symbol.length - 1);
798850
break;
799851
}
800852
}
@@ -808,7 +860,7 @@
808860
output = i === symbols.after.length - 1 ? output + locale.currency.symbol : numeral._.insert(output, locale.currency.symbol, -(symbols.after.length - (1 + i)));
809861
break;
810862
case ' ':
811-
output = i === symbols.after.length - 1 ? output + ' ' : numeral._.insert(output, ' ', -(symbols.after.length - (1 + i)));
863+
output = i === symbols.after.length - 1 ? output + ' ' : numeral._.insert(output, ' ', -(symbols.after.length - (1 + i) + locale.currency.symbol.length - 1));
812864
break;
813865
}
814866
}
@@ -889,7 +941,9 @@
889941
var space = numeral._.includes(format, ' %') ? ' ' : '',
890942
output;
891943

892-
value = value * 100;
944+
if (numeral.options.scalePercentBy100) {
945+
value = value * 100;
946+
}
893947

894948
// check for space before %
895949
format = format.replace(/\s?\%/, '');
@@ -909,7 +963,11 @@
909963
return output;
910964
},
911965
unformat: function(string) {
912-
return numeral._.stringToNumber(string) * 0.01;
966+
var number = numeral._.stringToNumber(string);
967+
if (numeral.options.scalePercentBy100) {
968+
return number * 0.01;
969+
}
970+
return number;
913971
}
914972
});
915973
})();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "numeral",
3-
"version": "2.0.4",
3+
"version": "2.0.5",
44
"description": "Format and manipulate numbers.",
55
"homepage": "http://numeraljs.com",
66
"author": {

0 commit comments

Comments
 (0)