Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

convert number to k m b javascript

function nFormatter(num) {
     if (num >= 1000000000) {
        return (num / 1000000000).toFixed(1).replace(/.0$/, '') + 'G';
     }
     if (num >= 1000000) {
        return (num / 1000000).toFixed(1).replace(/.0$/, '') + 'M';
     }
     if (num >= 1000) {
        return (num / 1000).toFixed(1).replace(/.0$/, '') + 'K';
     }
     return num;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: js mobile prevent image mousedown 
Javascript :: loopback date greater than 
Javascript :: exceljs read file from input 
Javascript :: js get array item by property 
Javascript :: javascript make beep 
Javascript :: convert string to array in vue js 
Javascript :: how to check if localhost javascript 
Javascript :: react native linking phone call 
Javascript :: javascript download json 
Javascript :: regex find img tag 
Javascript :: sweet alert 2 do action on confirm 
Javascript :: convert json string to json object in laravel 
Javascript :: username regex 
Javascript :: jquery check input is disable 
Javascript :: hello world expressjs 
Javascript :: get ng content element angular 2 
Javascript :: round to nearest hundredth javascript 
Javascript :: alert confirm prompt javascript 
Javascript :: randomColor 
Javascript :: es6 
Javascript :: bright green in javascript 
Javascript :: js query string 
Javascript :: truncate function react 
Javascript :: find the words separated by whitespace in a string javascript 
Javascript :: get method 
Javascript :: js style remove property 
Javascript :: fizzbuzz js 
Javascript :: check if an HTML element has any children 
Javascript :: package json accept any version 
Javascript :: setattribute disabled javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =