Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Parsing string with a different character

How can I parse this string "451:45" to a number? What I want to get is "451.45" as number.

Thanks in advance

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

  1. Replace the colon [:] with the dot [.] by using replace method of JS as –

    '451.45'.replace(":", ".");
    
  2. Now, we have desired string but as we need number so just parse it into Float by using parseFloat as –

    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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading