10 examples of 'number format jquery' in JavaScript

Every line of 'number format jquery' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
130formatNumber(num: string) {
131 return num.replace(/\d/g, match => symbolMap[match]).replace(/,/g, "،");
132}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

134function intlFormat(num) {
135 return new Intl.NumberFormat().format(Math.round(num * 10) / 10);
136}
55function unformat(number) {
56 return String(number).replace(/,/g,'');
57}
27format(num) {
28 if (num === 0) {
29 return '0';
30 }
31 let sig = Math.abs(num); // significand
32 let exponent = 0;
33 while (sig >= 1000 && exponent < 24) {
34 sig /= 1000;
35 exponent += 3;
36 }
37 while (sig < 1 && exponent > -24) {
38 sig *= 1000;
39 exponent -= 3;
40 }
41
42 const signPrefix = num < 0 ? '-' : '';
43 if (sig > 1000) {
44 return signPrefix + sig.toFixed(0) + this.prefixes[exponent];
45 }
46 return signPrefix + parseFloat(sig.toPrecision(3)) + this.prefixes[exponent];
47}
158function format_number(num, format) {
159 if (format === "float") {
160 return Number.parseFloat(num).toLocaleString();
161 } else {
162 return Number.parseInt(num).toLocaleString();
163 }
164}
410function formatNumber(number) {
411 var symbol = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ' ';
412 return String(number || 0).replace(/(\d)(?=(\d\d\d)+([^\d]|$))/g, "$1".concat(symbol));
413}
12export function formatNumber(format: string, value: number | null | undefined) {
13 return getInstance().format(format, value);
14}
39parse: function parse(value, culture, format) {
40 if (format) {
41 var data = (0, _deconstructNumberFormat2.default)(format),
42 negative = data.negativeLeftSymbol && value.indexOf(data.negativeLeftSymbol) !== -1 || data.negativeRightSymbol && value.indexOf(data.negativeRightSymbol) !== -1;
43
44 value = value.replace(data.negativeLeftSymbol, '').replace(data.negativeRightSymbol, '').replace(data.prefix, '').replace(data.suffix, '');
45
46 var halves = value.split(data.decimalChar);
47
48 if (data.integerSeperator) halves[0] = halves[0].replace(new RegExp('\\' + data.integerSeperator, 'g'));
49
50 if (data.decimalsSeparator) halves[1] = halves[1].replace(new RegExp('\\' + data.decimalsSeparator, 'g'));
51
52 if (halves[1] === '') halves.pop();
53
54 value = halves.join('.');
55 value = +value;
56
57 if (negative) value = -1 * value;
58 } else value = parseFloat(value);
59
60 return isNaN(value) ? null : value;
61},
1function formatNumber(n: number) {
2 return n > 9 ? n.toString() : '0' + n
3}
74function format(num) {
75 num = (num + '');
76 return [prefix, new Array(FORMAT_LEN - num.length).join('0'), num].join('');
77}

Related snippets