Skip to content

Instantly share code, notes, and snippets.

@jonathanborges
Last active November 27, 2018 18:03
Show Gist options
  • Save jonathanborges/14894c3e36feaf4fb72c4945963e2142 to your computer and use it in GitHub Desktop.
Save jonathanborges/14894c3e36feaf4fb72c4945963e2142 to your computer and use it in GitHub Desktop.
export const currency = (value, decimalPlaces = 2, symbol = true) => {
let formatedValue = parseFloat(value).toFixed(decimalPlaces)
.replace('.', ',')
.replace(/\d(?=(\d{3})+,)/g, '$&.')
return (symbol) ? `R$ ${formatedValue}` : formatedValue
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment