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.
    • 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

                          9

                          Online

                          1.7k

                          Users

                          11.9k

                          Topics

                          103.6k

                          Posts