Skip to content

Instantly share code, notes, and snippets.

@andreloureiro
Created December 21, 2016 15:00
Show Gist options
  • Save andreloureiro/006a9a51d7a06849f0120b4d8fc37e85 to your computer and use it in GitHub Desktop.
Save andreloureiro/006a9a51d7a06849f0120b4d8fc37e85 to your computer and use it in GitHub Desktop.
esnextbin sketch
<!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>
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));
})
{
"name": "esnextbin-sketch",
"version": "0.0.0",
"dependencies": {
"react": "latest",
"react-dom": "latest",
"pouchdb": "latest"
}
}
'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