Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to shorten billion in javascript

const formatCash = n => {
  if (n < 1e3) return n;
  if (n >= 1e3) return +(n / 1e3).toFixed(1) + "K";
};

console.log(formatCash(2500));
Comment

how to shorten billion in javascript

const formatCash = n => {
  if (n < 1e3) return n;
  if (n >= 1e3 && n < 1e6) return +(n / 1e3).toFixed(1) + "K";
  if (n >= 1e6 && n < 1e9) return +(n / 1e6).toFixed(1) + "M";
  if (n >= 1e9 && n < 1e12) return +(n / 1e9).toFixed(1) + "B";
  if (n >= 1e12) return +(n / 1e12).toFixed(1) + "T";
};

console.log(formatCash(1235000));
Comment

PREVIOUS NEXT
Code Example
Javascript :: string recurive in javascript 
Javascript :: datatables width issue for less number of columns 
Javascript :: How To Add Google Social Login Button 
Javascript :: Cannot load gulp: ReferenceError: primordials is not defined 
Javascript :: double and operator javascript 
Javascript :: 9.5. The Accumulator Pattern¶ 
Javascript :: javascript substtgin 
Javascript :: javascript create nodo 
Javascript :: mapbox gl js openpopup on a marker 
Javascript :: custom http vue 2 
Javascript :: AngularJS module can be created using ............ A. module.create(); B.angular.create(); C.angular.module(); D.var myModule = new module(); 
Javascript :: how to check if an image exists in js from cross origin 
Javascript :: number and type operators in javascript 
Javascript :: jquery to json diff 
Javascript :: absolute sum javascript 
Javascript :: Unexpected eval or arguments in strict mode 
Javascript :: settimeout react native focus text input 
Javascript :: vscode autosuggest background 
Javascript :: google script delete line 
Javascript :: vue expected string with value got number with value 
Javascript :: electron sample question 
Javascript :: convert utc time to specific timezone javascript 
Javascript :: agora token Renewal 
Javascript :: react js averta fonts not working in safari staging deployement 
Javascript :: jquery top 20 function 
Javascript :: node spawn stdout stderr 
Javascript :: odata filter query error Property access can only be applied to a single value. 
Javascript :: link the filename to the visible layer 
Javascript :: nested array generator for js 
Javascript :: fonction fleche js 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =