javascript format number as currency
function 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.67const 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:
- array sort js
- watchman watch-del-all, and react-native start --reset-cache
- json parse
- javascript remove item onclick
- how to check the extension of a file in javascript
- keyboard key codes
- express req get json
- ajax data not reflecting after refresh particular div jquery
- pegar qual domínio eu estou javascript
- closures in javascript
- javascript arrays codeburst
- type a promise
- align left text in reactstrap
- discord.js role permissions
- javascript moeda reais
- router-outlet' is not a known element angular
- span change jquery
- usematch react router
- how to get unique values from array in javascript without duplicate value
- disable input jquery
- jquery preventdefault
- string to date angular
- js string times
- console.log clear screen