Last active
November 27, 2018 18:03
-
-
Save jonathanborges/14894c3e36feaf4fb72c4945963e2142 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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