Skip to content

Instantly share code, notes, and snippets.

@wilcorrea
Forked from hamiltongabriel/numberInFormat.vue
Last active May 13, 2018 12:29
Show Gist options
  • Save wilcorrea/42a3510b08270d64f617cb8239e6f5fc to your computer and use it in GitHub Desktop.
Save wilcorrea/42a3510b08270d64f617cb8239e6f5fc to your computer and use it in GitHub Desktop.
export default function (value) {
const formatted = Number(value)
.toFixed(2)
.replace('.', ',')
.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1.")
return `R$ ${formatted}`
}
<template>
<div>
<p>Product one cost: {{ productOneCost | money }}</p>
<p>Product two cost: {{ productTwoCost | money }}</p>
<p>Product three cost: {{ productThreeCost | money }}</p>
</div>
</template>
<script>
import money from 'formatters/money'
export default {
data: () => ({
productOneCost: 998,
productTwoCost: 2399,
productThreeCost: 5300
}),
filters:{
money(value){
return money(value)
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment