Skip to content

Instantly share code, notes, and snippets.

@giulianobr
Created September 23, 2019 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giulianobr/b1c408239913a049f81699345b9918f6 to your computer and use it in GitHub Desktop.
Save giulianobr/b1c408239913a049f81699345b9918f6 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/pohisoruye
<!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>
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