parseInt("1 200р"); //возвращает 1 Can I do something to not take into account the space, or you need to first remove spaces from the string?
parseInt("1 200р"); //возвращает 1 Can I do something to not take into account the space, or you need to first remove spaces from the string?
Everything is quite simple - first, using a regular expression, delete everything except the numbers and periods, before replacing commas with periods, if any, and then converting it to the int type.
$("#btn").on("click", function() { var str = $("#blah").val(); alert(parseFloat(str.replace(",",".").replace(/[^0-9.]/gim, ""))); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input id="blah" value=""> <button id="btn">Calc</button> Source: https://ru.stackoverflow.com/questions/623545/
All Articles
parseInt. - Regent