HISE Logo Forum
    • Categories
    • Register
    • Login

    parseInt() value help

    Scheduled Pinned Locked Moved General Questions
    12 Posts 7 Posters 554 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Dan KorneffD
      Dan Korneff
      last edited by

      Hey guys,
      I'm using parsInt() to convert text from a label into an integer. Seems to work properly EXCEPT when I add a 0 in front of 8 or 9.

      01 = 1
      05 = 5
      08 = 0
      09 = 0
      90 = 90
      33333 = 33333
      Here's a simplified example:

      HiseSnippet 947.3ocsV0raaiCDlxwLn1sdQKPuWgbot.oFxo+s.EEqarcJL1FGg3jhdqkVh1lanHEnn5Vih9hzS6ix9xr222ftCEksjaTBZLvpSdl4al4aFNbn8Ux.ZRhTgbZb1xXJx4N3IKE5E8WPXBznAFEwDUB0USSznCWFSRRngHGmcdiAgSi5nru+82NjvIh.ZgJD5cRV.8srHltPqeuemw4GQBomwhJg9o8FEHE8kbYJvlcvdnXRvEj4zwDCrZXjytCCYZoZhl.jAvbnLb4jEx+TXw+NVBaJmZD5hl.AxpF0eAiG5upRSPHm59E08N15993iYgr05Kp+6lYvsvix8.mZaRo5aPotWEkNRxCMA3JnmSI5U2Ru6gmDnXw5BKFtca7HglplQf1dYZYwhp8fZ39R.gP2IhbA8HEHr1i1O2yae2m448nW1pYqlPyOQ69IhxkSlR4Z3vQ49J2gh4LAsSfhBUn4DScxz+fFnaa7p.YmDMQoyr2thP9VCvtP3VQm4TceYTrT.Bs2yZdOiW+fOGb89bvd1LUlHTKM5S37ovDT6Yoh.MSJZ+nVM+hArK7YR.SDmpg3aytI7s2SS+rNKlFPPhSjbZmXECxXF7UlrY2jrbe12M6Zxn0.MH+pkcqXfqTLVpom.To4WZ1n4Wa59illMqRalVfRx4P2sJy19903XaQZzTpZent4oz0.gwqMmeu8O27af8DoDPoXjfoOIllKWLgarYq5UV8PqK1xpJpwxZsibWFVgpKeABkOw.+57QCHZh4NUtN.WLUoYlp0Y.8SvBJ6MrF3AzjKzxXnordLC4f0YVake+K6bGwfJ6WviF6e9YtiO+3CGdJ5yEaxF2a4Zgd98nPGlj0Dc1AUJx6dUQ9VX6DY4X5WJl+866YF4.dh85hlNe0NyF6he32+VFjaPZNnTZ9KUUoowtN46yKmq+Ae4bckMq6h8e8oSFNvcz3yF9lMZWeTcMsqKuHDVGKCS4D8l6nMOFka.F72XYnYgmHgoWV9wpavhauJWb2sp4teR5dOrOSGrnZ9VqB9Byu+ey27mAagGNaFrdufr0wG89s8Mua.UNUlpYh4GSzJFLbfGmFMAlzBn.SDBJGRD1olYbyJ6YjMclITQXlv2gubicMxN4F6txHJhDnjeHvt.w7P6sxz.bRj8eLZfO1H61EkslD7C60wCEAu++gf.Sq3w.2q1mC1BedxV3yS2Bed1V3yy2BedwV3yuds9X9qWuNUKirWS.E9CyVn63LTX1RjMQh9O.ZJgeN
      

      Dan Korneff - Producer / Mixer / Audio Nerd

      1 Reply Last reply Reply Quote 0
      • d.healeyD
        d.healey
        last edited by

        parseInt sometimes does weird things. Use Math.round() instead.

        Libre Wave - Freedom respecting instruments and effects
        My Patreon - HISE tutorials
        YouTube Channel - Public HISE tutorials

        1 Reply Last reply Reply Quote 2
        • Christoph HartC
          Christoph Hart
          last edited by

          Link Preview Image
          Why JavaScript treats a number as octal if it has a leading zero

          var x = 010; console.log(x); //8 JS engine convert the number x to octal number. Why it happens? How can I prevent it?

          favicon

          Stack Overflow (stackoverflow.com)

          Dan KorneffD 1 Reply Last reply Reply Quote 3
          • Dan KorneffD
            Dan Korneff @Christoph Hart
            last edited by

            @Christoph-Hart thanks for this! Math.round gets the job done, so I'm happy :)

            Dan Korneff - Producer / Mixer / Audio Nerd

            1 Reply Last reply Reply Quote 1
            • Casey KolbC
              Casey Kolb
              last edited by

              Welp, it's August, so "08" by JUCE time, and this just broke all of my licensing systems lol. Time for an update to Math.round()

              Casey Kolb
              Founder & CEO of Lunacy Audio
              Composer | Producer | Software Developer

              1 Reply Last reply Reply Quote 2
              • Christoph HartC
                Christoph Hart
                last edited by

                Wow that sounds super annoying.

                If you want to globally deactivate octal number parsing, just make that function return always false:

                Link Preview Image
                HISE/hi_scripting/scripting/engine/JavascriptEngineParser.cpp at e4b8330a3c6b19b333b3544e9f4f599f3ce9726d 路 christophhart/HISE

                The open source framework for sample based instruments - HISE/hi_scripting/scripting/engine/JavascriptEngineParser.cpp at e4b8330a3c6b19b333b3544e9f4f599f3ce9726d 路 christophhart/HISE

                favicon

                GitHub (github.com)

                NatanN Casey KolbC 2 Replies Last reply Reply Quote 2
                • NatanN
                  Natan @Christoph Hart
                  last edited by Natan

                  @Christoph-Hart Thanks Christoph
                  Is This Helps To Fix The Frontendmacros Aswell?
                  Values Looks Strange There Too馃憦

                  1 Reply Last reply Reply Quote 0
                  • NatanN
                    Natan
                    last edited by

                    Update:
                    Return False is NOT The Answer :/
                    And Console, Shows This Error, Even In A Project WIth Nothing Than GUI Size

                    Line 1, column 28: Syntax error in numeric constant {SW50ZXJmYWNlfHwyN3wxfDI4}
                    
                    1 Reply Last reply Reply Quote 0
                    • Casey KolbC
                      Casey Kolb @Christoph Hart
                      last edited by

                      @Christoph-Hart It's all good. It was a 5 minute fix, but a several hour debug haha. Fortunately, I don't think it broke the compiled plugin.

                      Casey Kolb
                      Founder & CEO of Lunacy Audio
                      Composer | Producer | Software Developer

                      1 Reply Last reply Reply Quote 0
                      • C
                        civet
                        last edited by

                        confused 馃槙

                        I just used this function to parse date and time. It's OK when using javascript in browser.

                        for(var i = 0; i < 10; i++)
                            console.log(parseInt("0" + i));
                        
                        // 0 1 2 3 4 5 6 7 8 9
                        

                        but weird in HISE:

                        for(i = 0; i < 10; i++)
                        	Console.print(parseInt("0" + i));
                        
                        // 0 1 2 3 4 5 6 7 0 0
                        

                        finally, I do a trick:

                        for(i = 0; i < 10; i++)
                        	Console.print(parseInt("+0" + i));
                        
                        // 0 1 2 3 4 5 6 7 8 9
                        
                        LindonL 1 Reply Last reply Reply Quote 0
                        • LindonL
                          Lindon @civet
                          last edited by

                          @civet HISEScript != javascript

                          HISE Development for hire.
                          www.channelrobot.com

                          C 1 Reply Last reply Reply Quote 0
                          • C
                            civet @Lindon
                            last edited by civet

                            @Lindon Yes, I know. I have read the docs carefully.

                            but parseInt() is very commonly used in scripts. and it's likely parseInt() in HISE does not support the second parameter.

                            parseInt("010", 10); // always return 8 in HISE
                            
                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post

                            12

                            Online

                            1.7k

                            Users

                            11.9k

                            Topics

                            103.6k

                            Posts