I am stuck in a solution in which I am trying to convert the string to integer, but it truncates the zeroes after comma.Any help on this is much appreciated. For example,
parseInt("3,50,000") // 3 ==> what i actually need is 3,50,00 of integer type
I am stuck in a solution in which I am trying to convert the string to integer, but it truncates the zeroes after comma.Any help on this is much appreciated. For example,
parseInt("3,50,000") // 3 ==> what i actually need is 3,50,00 of integer type
This:
console.log(parseInt("3,50,000".replace(/,/ig, ''), 10));
Displays:
350000
You must remove commas used for thousands (, millions...) markers (here I replace with empty strings) before parsing an int from a string.
Also, always include the radix, here 10 meaning parse as a base 10 integer.
I used a regular expression to perform the replacement because it is quite efficient, having to process the string only once.