HISE Logo Forum
    • Categories
    • Register
    • Login

    Lose the .0 in label / value

    Scheduled Pinned Locked Moved General Questions
    13 Posts 4 Posters 575 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.
    • DanHD
      DanH @ustk
      last edited by

      @ustk @Matt_SF thanks both, I've written it like this in the callback, is there an easier way?

      local x = Math.round(value);
      LabelValue.set("text", x);
      

      DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
      https://dhplugins.com/ | https://dcbreaks.com/
      London, UK

      ustkU 1 Reply Last reply Reply Quote 0
      • ustkU
        ustk @DanH
        last edited by

        @DanH you don't need to create a variable for this as it is simple to understand, you can directly put the round function inside the label set

        Can't help pressing F5 in the forum...

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

          @DanH said in Lose the .0 in label / value:

          even if the value is an integer, eg 1.0. 2.0

          Those aren't integers ;)

          You could also use parseInt()

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

          DanHD ustkU 2 Replies Last reply Reply Quote 0
          • DanHD
            DanH @d.healey
            last edited by

            @d-healey thanks, should have used a full stop rather than a comma 😆

            DHPlugins / DC Breaks | Artist / Producer / DJ / Developer
            https://dhplugins.com/ | https://dcbreaks.com/
            London, UK

            1 Reply Last reply Reply Quote 0
            • Matt_SFM
              Matt_SF @ustk
              last edited by

              @ustk said in Lose the .0 in label / value:

              @DanH @Matt_SF doubleToString parameters are the other way round Engine.doubleToString(double value, int digits)
              In this case a simple Math.round(value) will remove the last digit the other function can't

              My mistake, sorry 👍

              Develop branch
              Win10 & VS17 / Ventura & Xcode 14. 3

              1 Reply Last reply Reply Quote 0
              • ustkU
                ustk @d.healey
                last edited by ustk

                @d-healey said in Lose the .0 in label / value:

                You could also use parseInt()

                I don't like the parseInt function, because, in some (rare) cases, it treats a leading zero as an octal number. I agree this is rarely the case (it happens for instance when dealing with dates).

                example:

                Console.print(parseInt("0500"));	// => 320
                Console.print(Math.round("0500"));	// => 500
                

                Though in this case, it is not a problem to use it, I just personally feel like wanting to stay away from it :)

                EDIT:
                I just discovered that when not using a string, both are converting octal to base10!
                (this makes sense since they are written in an octal fashion...)

                Console.print(parseInt(0500));		// => 320
                Console.print(Math.round(0500));	// => 320
                

                But I don't see a scenario where this could happen anyway...

                Can't help pressing F5 in the forum...

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

                  @ustk Is there an efficiency difference between the two functions?

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

                  ustkU 2 Replies Last reply Reply Quote 0
                  • ustkU
                    ustk @d.healey
                    last edited by

                    @d-healey That is what I'm wondering... Making a benchmark to see...

                    Can't help pressing F5 in the forum...

                    1 Reply Last reply Reply Quote 0
                    • ustkU
                      ustk @d.healey
                      last edited by

                      @d-healey Another reason to stick with Math.round() !

                      reg a = 0;
                      
                      inline function round(dec)
                      {
                      	return Math.round(dec);
                      }
                      
                      Console.startBenchmark();
                      
                      for (i=0;i<100000;i+=0.3333)
                      {
                      	a = parseInt(i);	// 130-135ms
                      	a = Math.round(i);	// 50-53ms
                      	a = round(i);		// 68-70ms
                      }
                      	
                      Console.stopBenchmark();
                      

                      Can't help pressing F5 in the forum...

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

                        @ustk Good test, I get similar results on my system. So Math.round() is the way to go!

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

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post

                        22

                        Online

                        1.8k

                        Users

                        12.0k

                        Topics

                        104.1k

                        Posts