Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

How to abreviate digits in js

function abbreviateNumber(value) {
    var newValue = value;
    if (value >= 1000) {
        var suffixes = ["", "k", "m", "b","t"];
        var suffixNum = Math.floor( (""+value).length/3 );
        var shortValue = '';
        for (var precision = 2; precision >= 1; precision--) {
            shortValue = parseFloat( (suffixNum != 0 ? (value / Math.pow(1000,suffixNum) ) : value).toPrecision(precision));
            var dotLessShortValue = (shortValue + '').replace(/[^a-zA-Z 0-9]+/g,'');
            if (dotLessShortValue.length <= 2) { break; }
        }
        if (shortValue % 1 != 0)  shortValue = shortValue.toFixed(1);
        newValue = shortValue+suffixes[suffixNum];
    }
    return newValue;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: mobile number validation in javascript with country code 
Javascript :: round to nearest decimal javascript 
Javascript :: array json 
Javascript :: filter dates javascript 
Javascript :: jquery datatable passing of parameters 
Javascript :: mongoose response to object 
Javascript :: js listen localstorage change 
Javascript :: react native toast message 
Javascript :: javascript foreach url parameter 
Javascript :: search to enter key react 
Javascript :: material ui dark theme 
Javascript :: js unique string array 
Javascript :: innertext javascript 
Javascript :: try catch in react native 
Javascript :: jquerry get url 
Javascript :: classlist 
Javascript :: express cors specific origins 
Javascript :: javascript set object key by variable 
Javascript :: javascript require 
Javascript :: puppeteer wait for page loadjavascript 
Javascript :: Error: ENOENT: no such file or directory, mkdir 
Javascript :: javascript append html 
Javascript :: rich editor react 
Javascript :: how to delete a message by its id discord.js 
Javascript :: get in redis 
Javascript :: javascript math absolute 
Javascript :: react native dimensions 
Javascript :: event.currenttarget 
Javascript :: react grid 
Javascript :: node terminal readline console 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =