how can i convert "570.581,88" into an integer and sort accordingly?
In JavaScript parseInt() function (or a method) is used to convert the passed in string parameter or value to an integer value itself. This function returns an integer of base which is specified in second argument of parseInt() function.
Converting Variables to Numbers There are 3 JavaScript methods that can be used to convert variables to numbers: The Number() method. The parseInt() method. The parseFloat() method.
Description. The parseInt function converts its first argument to a string, parses that string, then returns an integer or NaN . If not NaN , the return value will be the integer that is the first argument taken as a number in the specified radix .
var s = "570.581,88";
// Format as American input
s = s.replace(/\./g,'').replace(',','.');
// Integer
var i = parseInt(s,10);
// Floats
var f1 = parseFloat(s);
var f2 = s*1;
var f3 = +s;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With