Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript, digit thousand formatting, number formating js, regexp, number comma seperation js

const toThousands = (price) => {   
return price.replace(new RegExp(`(?!^)(?=(d{3})+${price.includes('.') ? '.' : '$'})`, 'g'), ',')   
} 

toThousands('123456789')     // '123,456,789' 
toThousands('123456789.123') // '123,456,789.123' 
toThousands('123')           // '123'
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript sort by date descending 
Javascript :: how to access parent function from iframe 
Javascript :: What is the syntax to export a function from a module in Node.js 
Javascript :: dynamic folder import javascript 
Javascript :: js php number format 
Javascript :: npm shrinkwrap primordials 
Javascript :: add click event listener javascript 
Javascript :: add onclick event jquery button 
Javascript :: generate combinations of values from multiple array javascript 
Javascript :: how to remove duplicates in array in javascript 
Javascript :: scrapy javascript 
Javascript :: create component with module and routing in angular 8 
Javascript :: infinity javascript 
Javascript :: hex string to buffer nodejs 
Javascript :: Access to XMLHttpRequest has been blocked by CORS policy 
Javascript :: importing json file in javascript 
Javascript :: Date gethours js 
Javascript :: js sleep 
Javascript :: react hook form with yup resolver 
Javascript :: adding document to firebase firestore 
Javascript :: jquery force page to reload on viewport resize 
Javascript :: javascript ternary 
Javascript :: ajax syntax in javascript 
Javascript :: array sort by two properties 
Javascript :: nuxt emit 
Javascript :: javascript date convert to unix 
Javascript :: camelcase to normal text javascript 
Javascript :: get promise result from json() javascript 
Javascript :: difference between indexof and search in javascript 
Javascript :: clear html element javascript 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =