Created
November 24, 2016 12:05
-
-
Save Reelix/b4e321dc2c5d39997d493729123aeb58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
function formatCurrency() | |
{ | |
// Get the values from the text-boxes | |
var symbol = document.getElementById('formatCurrencySymbol').value; | |
var number = parseFloat(document.getElementById('formatCurrencyNumber').value); | |
var decimalPlaces = document.getElementById('formatCurrencyDecimalPlaces').value; | |
// Do the formatting - Regex here! | |
var result = symbol + number.toFixed(decimalPlaces).replace(/(\d)(?=(\d{3})+\.)/g, "$1,"); | |
// Display the result | |
alert(result); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment