Created
September 23, 2019 11:27
-
-
Save giulianobr/b1c408239913a049f81699345b9918f6 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/pohisoruye
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
const nm = 10; | |
function formatNumber(nb){ | |
let number = nb.toFixed(2); | |
let fmt = number.toString(); | |
const cents = fmt.slice(-2); | |
const intpart = fmt.split('.')[0] | |
console.log(cents); | |
return fmt; | |
} | |
function currencyFormatDE(num) { | |
return ( | |
num | |
.toFixed(2) // always two decimal digits | |
.replace('.', ',') // replace decimal point character with , | |
.replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1.') | |
) | |
} | |
console.log(currencyFormatDE(nm)) | |
formatNumber(nm); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">const nm = 10; | |
function formatNumber(nb){ | |
let number = nb.toFixed(2); | |
let fmt = number.toString(); | |
const cents = fmt.slice(-2); | |
const intpart = fmt.split('.')[0] | |
console.log(cents); | |
return fmt; | |
} | |
function currencyFormatDE(num) { | |
return ( | |
num | |
.toFixed(2) // always two decimal digits | |
.replace('.', ',') // replace decimal point character with , | |
.replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1.') | |
) | |
} | |
console.log(currencyFormatDE(nm)) | |
formatNumber(nm);</script></body> | |
</html> |
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
const nm = 10; | |
function formatNumber(nb){ | |
let number = nb.toFixed(2); | |
let fmt = number.toString(); | |
const cents = fmt.slice(-2); | |
const intpart = fmt.split('.')[0] | |
console.log(cents); | |
return fmt; | |
} | |
function currencyFormatDE(num) { | |
return ( | |
num | |
.toFixed(2) // always two decimal digits | |
.replace('.', ',') // replace decimal point character with , | |
.replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1.') | |
) | |
} | |
console.log(currencyFormatDE(nm)) | |
formatNumber(nm); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment