jquery number format thousand k

Solutions on MaxInterview for jquery number format thousand k by the best coders in the world

showing results for - "jquery number format thousand k"
Davide
24 Oct 2017
1function nFormatter(num, digits) {
2  var si = [
3    { value: 1, symbol: "" },
4    { value: 1E3, symbol: "k" },
5    { value: 1E6, symbol: "M" },
6    { value: 1E9, symbol: "G" },
7    { value: 1E12, symbol: "T" },
8    { value: 1E15, symbol: "P" },
9    { value: 1E18, symbol: "E" }
10  ];
11  var rx = /\.0+$|(\.[0-9]*[1-9])0+$/;
12  var i;
13  for (i = si.length - 1; i > 0; i--) {
14    if (num >= si[i].value) {
15      break;
16    }
17  }
18  return (num / si[i].value).toFixed(digits).replace(rx, "$1") + si[i].symbol;
19}
20
21/*
22 * Tests
23 */
24var tests = [
25  { num: 1234, digits: 1 },
26  { num: 100000000, digits: 1 },
27  { num: 299792458, digits: 1 },
28  { num: 759878, digits: 1 },
29  { num: 759878, digits: 0 },
30  { num: 123, digits: 1 },
31  { num: 123.456, digits: 1 },
32  { num: 123.456, digits: 2 },
33  { num: 123.456, digits: 4 }
34];
35var i;
36for (i = 0; i < tests.length; i++) {
37  console.log("nFormatter(" + tests[i].num + ", " + tests[i].digits + ") = " + nFormatter(tests[i].num, tests[i].digits));
38}
Stefano
20 Nov 2019
1function kFormatter(num) {
2    return Math.abs(num) > 999 ? Math.sign(num)*((Math.abs(num)/1000).toFixed(1)) + 'k' : Math.sign(num)*Math.abs(num)
3}
4    
5console.log(kFormatter(1200)); // 1.2k
6console.log(kFormatter(-1200)); // -1.2k
7console.log(kFormatter(900)); // 900
8console.log(kFormatter(-900)); // -900
queries leading to this page
can a number be over 1 2c000 2c000 in javascript 3fformat a number in javascript as k 2fm 2fbjs function m 28a 2cb 2cc 3d3000 29number to thousand javscriptthousands k format jsconvert number to k and m javascriptformat thousands k jsjs convert number k m to fullshorten number into k m or billion javascripthow to show number format in thousands in javascripthow to make number display like amout jsjs thousand to khow to convert number into k thousand m million and billion suffix in javascriptvalue formatter js thousands millionsnumber to thousand converter jqueryformat thousands javascriptjavascript format number with thousand commahtml number formatting k mjavascript conver number into k and mjavascript format number thousands millionsjs string number k to number js shortnumber knumber conversion from digit to k format in nodejsjs transform 9000 to 1000numeraljs format thousands with kjs format number thousands separatorformat the number in m 2ck 2ct javascriptnumberformat million with m javascript1000 to k in javascriptintl format round 1000 kconvert numbers to thousands k jsjavascript truncate number with kjavascript currency format billion to bformat numbers to nearest thousands such as kilos 2c millions 2c billions jshow to format numbers in thousands in jsjs tousands to kformat number from 2 5k to fulljs number format kjquery how to show large number currencyjs number format every 3 digit after comaconvert number to k in javascriptjavascript format number to k m replace 28 60 billion 60 26 26 60 60 2c 600 60 29javascript price format with kilojs format thousandsjs value formatter milions thousandsk 2cm format number jquerynum to 1k jsmake k and m numbers javascriptjavascript format number thousands separatorformat number in k in nodejs expressjavascript if value is upto 1000 use k valueformatting trillion javasxriptnodejs number to kjavascript number format thousands separatorsimplify large numbers to k jsjquery add k to numberjs format to millionsjavascript add k to utr numberformat monet number javascriptjavascript convert numbers to kjs number format to kformat number in t 120m 2c 120k jsjs make number larger than 1000 kjavascript numbers with kformatting thousands with decimals javascriptjquery format number millionsturning 2000 into 2k djangojs format number with thousands separator not decimal placesjavascript format number with kjavascript add m 2c b 2c kjs conver number to kjavascript convert number into k for thousand 27conver value to k and m npmjavascript nformatter price with letter denoting thousandsjavascript number format thousand separatorreturn 28num 2f 1000 29 tofixed 28decimal 29 2b 27k 27 3bfor i in k in jsformat k m javascript1000 as k reactjavascript convert values to k and mjquery number format thousand separatorshow no k or m in javascriptjavascript number to k and mjavascript format number as 2kremove k from 10000 amount in javascriotformat number 22k 22 react nativejs format money with k 2cmjavascript show tousands k without changing valueconvert to thousands jsformatter curreny to kilo jsreplace zeros with k javascripttypescript convert number in thousand to kconvert n1000 to 1 000 javascriptjs calculation formatting thousandsjs format number by thousand and millionshorten long numbers to k 2fm 2fb jqueryformatting cash value with k m b tturn k into number javascriptjavascript short number formatformat number javascript k thousandsformat numbers in ms and ks in javascriptcount thousands in node jsdisplay number with javascript ending with k or mhow to dynamically change number units between k 2f m 2f b angularjavascript reduce large numbers with kformat number thousands javascript dotnumber format with k suffix javascriptvuejs convert amount 1000 to 1kconvert 20 2c000 to 20000 in javascriptjquery number format thousand khow to display number in thousands javascriptconvert value to k nodejsconvert number to k in nodejsjquery number format thousand k