Skip to content

Instantly share code, notes, and snippets.

@xesjkeee
Last active March 19, 2019 21:28
Show Gist options
  • Save xesjkeee/65e726519bd170744951795a8efeb36c to your computer and use it in GitHub Desktop.
Save xesjkeee/65e726519bd170744951795a8efeb36c to your computer and use it in GitHub Desktop.
Price Format
Vue.filter('priceFormat', function (val) {
if (typeof val !== 'number' && typeof val !== 'string') return val
if (typeof val === 'string') val = parseInt(val)
const res = Math.round(val * 100) / 100
return res.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ' ')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment