javascript convert number from thousands to k and millions to m
// converts number to string representation with K and M.
// toFixed(d) returns a string that has exactly 'd' digits
// after the decimal place, rounding if necessary.
function numFormatter(num) {
if(num > 999 && num < 1000000){
return (num/1000).toFixed(1) + 'K'; // convert to K for number from > 1000 < 1 million
}else if(num > 1000000){
return (num/1000000).toFixed(1) + 'M'; // convert to M for number from > 1 million
}else if(num < 900){
return num; // if value < 1000, nothing to do
}
}
Also in JavaScript:
- datatable sAjaxSource get output
- ignore node modules
- javascript push and concat
- dont starve together
- convert int to float in javascript
- javascript get url parameters
- find unique elements in array javascript
- react native add two view
- how to compare elements in an array
- angular 6 reload current page
- how to get only citnames in google maps api js
- How to show confirm message before delete using jquery
- python convert requests response to json
- date object javascript
- trigger jquery autocomplete on click
- how to print to screen in javascript
- get actual url in variable
- js shortcut
- how to identify specific letter from a string in javascript
- how to solve Could not write JSON: Infinite recursion (StackOverflowError)
- express static
- href javascript void
- get all entries in object as array hjs
- webpack setup proxy manual