How can I parse this string "451:45" to a number? What I want to get is "451.45" as number.
Thanks in advance
>Solution :
-
Replace the colon [:] with the dot [.] by using
replacemethod of JS as –'451.45'.replace(":", "."); -
Now, we have desired string but as we need number so just parse it into Float by using
parseFloatas –parseFloat('451.45');Please find the complete code as –
let str = '451:45'; str = str.replace(":", "."); str = parseFloat(str);
Let me know in comments if you need any help further.
Thanks.