Created
October 11, 2013 09:28
-
-
Save fjaguero/6932045 to your computer and use it in GitHub Desktop.
JS Regex: Adds thousands separator to a number.
This file contains hidden or 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
// Adds the thousands separator | |
function numberWithThousands(x) { | |
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, "."); | |
} |
formatter={(value) => ` ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')} parser={(value) => value.replace(/\$\s?|(,*)/g, '')}
I'm using this, with the comma works fine but i want to use a dot as a thousand separator and a comma for decimals. But if i put a dot instead of a comma i get this result 2.0.0.0.0.000 can someone help me?
@OmarNassar01 Hi, did you find solution?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@OmarNassar01 have a look at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString