Reputation: 4848
I'm trying to cast a value from string to decimal but it doesn't give me the correct value this my code :
operation['montant'] = "12 000,00" ;
var value = parseFloat((operation['montant']).replace(",", "."));
alert(value);
alert(value) give me only 12
Can someone help me thank you in advance
Upvotes: 1
Views: 621
Reputation: 1450
operation['montant'] = "12 000,00" ;
var value = parseFloat((operation['montant']).replace(",", ".").replace(" ", ""));
alert(value);
This will replace spaces with, well, nothing. JS's parse float stops trying to parse something at a white space, so you were only getting 12. Hope this works for you.
Upvotes: 2