moneyFormat
by kordarei
HTML
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="app">
{{ value | moneyFormat }}
</div>
</body>
</html>
JavaScript
new Vue({
el: '#app',
data() {
return {
value: '1000'
}
},
filters: {
moneyFormat(amount) {
const negativeSign = amount < 0 ? "-" : "";
let i = parseInt(amount = Math.abs(Number(amount) || 0).toFixed(2)).toString();
let j = (i.length > 3) ? i.length % 3 : 0;
return negativeSign + (j ? i.substr(0, j) + '.' : '')
+ i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + '.')
+ (',' + Math.abs(amount - i).toFixed(2).slice(2))
+ ' RSD';
}
}
})