switchon@lavalamp.biz
+27(0) 83 419 4851 / +27(0) 21 036 1165
Application & software development
Get A Quote

    • Home
    • Services
      • Application & software development
      • Outsourced software development
      • Project based resourcing
      • Digital marketing & consulting
      • Graphic design & consulting
      • UI / UX design & consulting
      • Recruitment services
      • Lease an expert
    • About
      • How we work
      • NBConsult Group
      • Partners
      • Lightbox Digital
    • Blog
    • Join us
    • Contact

    • Home
    • Services
      • Application & software development
      • Outsourced software development
      • Project based resourcing
      • Digital marketing & consulting
      • Graphic design & consulting
      • UI / UX design & consulting
      • Recruitment services
      • Lease an expert
    • About
      • How we work
      • NBConsult Group
      • Partners
      • Lightbox Digital
    • Blog
    • Join us
    • Contact

    • Home
    • Services
      • Application & software development
      • Outsourced software development
      • Project based resourcing
      • Digital marketing & consulting
      • Graphic design & consulting
      • UI / UX design & consulting
      • Recruitment services
      • Lease an expert
    • About
      • How we work
      • NBConsult Group
      • Partners
      • Lightbox Digital
    • Blog
    • Join us
    • Contact

    • Home
    • Services
      • Application & software development
      • Outsourced software development
      • Project based resourcing
      • Digital marketing & consulting
      • Graphic design & consulting
      • UI / UX design & consulting
      • Recruitment services
      • Lease an expert
    • About
      • How we work
      • NBConsult Group
      • Partners
      • Lightbox Digital
    • Blog
    • Join us
    • Contact
    client budget
    How And When To Ask Clients What Their Budget Is
    Mar 7, 2022
    ubuntu
    Help! I’ve Had To SSH Into A Linux Box And Don’t Know What To Do
    Apr 5, 2022

    Many Ways To Skin A Cat – If A Cat Was A String Value

    Categories
    • Languages / Tech areas
    • Web Development
    Tags
    • code
    • coding
    • development
    • javascript
    • PHP
    • software developer
    • software development
    • String
    • tips
    string value
    string value

     

    Ways to convert a string to a number.

     

    1. ParseInt()

    ParseInt allows for spaces. One downside is that a decimal number passed in will be rounded off to the nearest decimal point and converted to a number.

    string to number conversion

     

    1. Number()

    Number() could be used instead of parseInt() because it can convert a decimal number without rounding it down. Returns NAN when value cannot be converted.

    string to number conversion

     

    1. The Unary Operator

    Add the plus operator before any string value and it will be converted to a number.

    string to number conversion

     

    1. ParseFloat()

    Works better with decimal numbers. Will return NAN if conversion is not possible and only converts the first number when multiple string values are passed in.

    string to number conversion

     

    1. floor()

    Using Math.floor() also isn’t kind to decimal conversions because it returns the largest number less than or equals to the number passed in.

    string to number conversion

     

    1. Multiplication

    Simply multiplying your string with 1, converts it to a number. It’s also decimal friendly.

    string to number conversion

     

    1. Double Tilde

    A double tilde (~~) works the same as the unary operator (+), except it will round down any decimal number.

    string to number conversion

    Happy coding 🙂

    Contact us


      Related posts:

      angularUpdating A Primitive Type Variable From A Service In Angular sending files with auxiliary dataSimple Way To Send A File With Auxiliary Data Via Axios In VueJS dynamic doughnut graph using laravel vue componentDynamic Doughnut Graph Using Laravel Vue Component 9 tips to prevent programmer burnout9 Tips To Prevent Programmer Burnout
      Share
      0
      Werner Bestbier
      Werner Bestbier
      Werner is a front-end developer with a background in design. Making a users web-surfing life easy is his game. His preferred language/framework is Javascript and Angular.

      Leave a Reply Cancel reply

      Your email address will not be published. Required fields are marked *

      Lava Lamp Lab


      Like technology, a lava lamp constantly changes form, producing new conditions with every passing moment



      lava lamp lab facebook   lava lamp lab twitter   lava lamp lab linkedin   lava lamp lab instgram

      Services


      Application & software development

      Outsourced software development

      Project based resourcing

      Digital marketing & consulting

      Graphic design & consulting

      UI / UX design & consulting

      Contact Us


      +27(0) 83 419 4851

      +27(0) 21 036 1165


      switchon@lavalamp.biz


      Unit 4 Monaco Square,
      14 Church Street,
      Durbanville,
      Cape Town, 7550

      NBConsult Group


      nbconsult
      nbconnect msp
      nbclearning
      river broadband
      designer needed
      © 2023 Lava Lamp Lab (Pty) Ltd | All Rights Reserved | Privacy Policy
      Contact us now

        Application & software development

          Outsourced software development

            Project based resourcing

              Digital marketing & consulting

                Graphic design & consulting

                  UI/UX design & consulting

                    Lease an expert

                      Recruitment services

                        We are using cookies to give you the best experience on our website.

                        You can find out more about which cookies we are using or switch them off in settings.

                        Lava Lamp Lab
                        Powered by  GDPR Cookie Compliance
                        Privacy Overview

                        This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

                        Strictly Necessary Cookies

                        Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.

                        If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.

                        3rd Party Cookies

                        This website uses Google Analytics to collect anonymous information such as the number of visitors to the site, and the most popular pages.

                        Keeping this cookie enabled helps us to improve our website.

                        Please enable Strictly Necessary Cookies first so that we can save your preferences!

                        Cookie Policy

                        More information about our Cookie Policy