javascript format currency
const formatToCurrency = amount => {
return "$" + amount.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, "$&,");
};
formatToCurrency(12.34546); //"$12.35"
formatToCurrency(42345255.356); //"$42,345,255.36(12345.67).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,'); // 12,345.67function formatToCurrency(amount){
return (amount).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
}
formatToCurrency(12.34546); //"12.35"
formatToCurrency(42345255.356); //"42,345,255.36"
Also in JavaScript:
- prevent form submission on onsubmit function calls
- node js get file name without extension
- count value a to b character javascript
- definition destructuring react
- ngmodel div angular 7
- nodejs add element to array
- mongodb distancefield to kms
- vue dynamic create watch
- reload a child component in angular
- output event angular
- react route props
- kill all node process ubunut
- javascript open in new window not tab
- mdn foreach
- jquery modify style attribute
- array javascript django
- javascript string contains character
- jquery ajax 500 error handling
- javascript variables
- javascript hover event
- javascript forever loop
- how to smooth scroll in javascript
- gatsby-plugin-create-client-paths
- javascript get array size