Skip to content

Commit

Permalink
feat: add filter currency Integer
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandorjesus committed Feb 13, 2022
1 parent 640f466 commit a9cdb76
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/filters/currency.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,20 @@ Vue.filter('currency', (value, noSign) => {

return formated;
});

Vue.filter('currencyInteger', (value, noSign, digits = 2) => {
let val = value.toString();
val = digits == 2 ? val : val.slice(0, -2);
const num = [
parseInt(val),
val.substring(0, val.length - 2) + '.' + val.substring(val.length - 2),
][Number(digits === 2)];

const formated = new Intl.NumberFormat('pt-BR', {
style: noSign ? 'decimal' : 'currency',
currency: 'BRL',
minimumFractionDigits: digits,
}).format(num);

return formated;
});

0 comments on commit a9cdb76

Please sign in to comment.