I am trying to figure out how to convert an amount to an integer in Javascript. E.g.
Input 10.555,95
Output 1055595
Input 9.234,77
Output 923477
I was thinking about removing the dot and the comma, but I don't know if that would be efficient
I am trying to figure out how to convert an amount to an integer in Javascript. E.g.
Input 10.555,95
Output 1055595
Input 9.234,77
Output 923477
I was thinking about removing the dot and the comma, but I don't know if that would be efficient
Based on your use cases, you want to make an integer by replacing the special chars in a string. You need to replace like this
parseInt("9.234,77".replace(",","").replace(".",""))
Since you wish to remove everything (regardless of formatting), you could replace any non-numeric characters and then force their type:
var intValue = + '10.555,95'.replace(/[^\d]/g,''); // == 1055595;
parseFloat('10.555,95'.replace('.','').replace(',',''));
inspired by this answer: JavaScript: Parse a string to a number?