How to use the numberFormat function from underscore.string

Find comprehensive JavaScript underscore.string.numberFormat code examples handpicked from public code repositorys.

7
8
9
10
11
12
13
14
15
16
17
module.exports = function(app) {
    // Include string format helpers
    app.locals.num = function(num, digits) {
        var sigDigits = Number(digits);
        if (isNaN(sigDigits)) sigDigits = 2;
        return s.numberFormat(Number(num), sigDigits);
    };


    app.locals.timeAgo = function(time) {
        return moment(time).fromNow(true);
fork icon4
star icon4
watch icon0

68
69
70
71
72
73
74
75
76
77
    let num = this.parseNumber(ev.target.value);
    ev.target.value = this.formatNumber(num);
},

formatNumber(value) {
    return s.numberFormat(value, this.props.decimalDigits, ',', '.');
},

parseNumber(value) {
    if (_.isNumber(value)) {
fork icon0
star icon3
watch icon0

+ 2 other calls in file

57
58
59
60
61
62
63
64
65
66
67
	if (bytes == 0) return '0 octets';
	var k = 1024,
		dm = decimals || 2,
		sizes = ['octets', 'Ko', 'Mo', 'Go'],
		i = Math.floor(Math.log(bytes) / Math.log(k));
	return _string.numberFormat(bytes / Math.pow(k, i), dm, ',', ' ') + ' ' + sizes[i];
}


/**
 * Format float
fork icon0
star icon1
watch icon0

+ 3 other calls in file

21
22
23
24
25
26
27
28
29

selectPayload: function() {
	return _.map(this.toJSON(), function(item) {
		return {
			'value': item.tax_id,
			'label': _string.numberFormat(parseFloat(item.vat_rate), 2, ',', ' ') + ' %'
		};
	});
}
fork icon0
star icon1
watch icon0

335
336
337
338
339
340
341
342
343
344
  return new NyxString(s);
}

"number-format"(decimals) {
  decimals = decimalParameterToInt(decimals);
  const res = s.numberFormat(this.__value__, decimals);
  return new NyxString(res);
}

"numeric?"() {
fork icon0
star icon0
watch icon0

+ 7 other calls in file