Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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'
 
PREVIOUS NEXT
Tagged: #digit #thousand #number #formating #number #comma #seperation #js
ADD COMMENT
Topic
Name
7+3 =