Created
November 23, 2016 22:33
-
-
Save Reelix/ba24fb564c4d004756949cdd04d74384 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