made with esnextbin
Created
December 21, 2016 15:00
-
-
Save andreloureiro/006a9a51d7a06849f0120b4d8fc37e85 to your computer and use it in GitHub Desktop.
esnextbin sketch
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"> | |
<title>ESNextbin Sketch</title> | |
<!-- put additional styles and scripts here --> | |
</head> | |
<body> | |
<div id="app"></div> | |
<input type="text" id="myInput"> | |
</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 input = document.getElementById('myInput'); | |
function formatCurrency(v, n, x) { | |
var re = '\\d(?=(\\d{' + (x || 3) + '})+' + (n > 0 ? '\\.' : '$') + ')'; | |
return Number(v).toFixed(Math.max(0, ~~n)).replace(new RegExp(re, 'g'), '$&,'); | |
}; | |
input.addEventListener('input', e => { | |
console.log(formatCurrency(e.target.value)); | |
}) |
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
{ | |
"name": "esnextbin-sketch", | |
"version": "0.0.0", | |
"dependencies": { | |
"react": "latest", | |
"react-dom": "latest", | |
"pouchdb": "latest" | |
} | |
} |
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
'use strict'; | |
var input = document.getElementById('myInput'); | |
function formatCurrency(v, n, x) { | |
var re = '\\d(?=(\\d{' + (x || 3) + '})+' + (n > 0 ? '\\.' : '$') + ')'; | |
return Number(v).toFixed(Math.max(0, ~ ~n)).replace(new RegExp(re, 'g'), '$&,'); | |
}; | |
input.addEventListener('input', function (e) { | |
console.log(formatCurrency(e.target.value)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment