Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to put coma between hundreds and thousands of any given number

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 271
    Comment on it

    Hello reader's! On a given number format if you want it to be customize like a figure with separated by (,) like 128,347,556. By using a function and in the function we will Preg Match the string with every hundreds and thousands You can use the code below :-

    function NumberToChange (youNumber) {
        return youNumber.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,")
    }
    
    print(NumberToChange(3675)); 
    Output:       3,675
    print(NumberToChange(589854));
    Output:     589,854
    print(NumberToChange(666656668)); 
    Output:     666,656,668
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: