Forum
    • Categories
    • Register
    • Login

    Lose the .0 in label / value

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

      @DanH

      Engine.doubleToString(numDecimal, value)
      

      If I remember correctly.

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

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

        @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

        Hise made me an F5 dude, any other app just suffers...

        DanHD Matt_SFM 2 Replies Last reply Reply Quote 0
        • 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

            Hise made me an F5 dude, any other app just suffers...

            1 Reply Last reply Reply Quote 0
            • David HealeyD
              David 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()

              Free HISE Bootcamp Full Course for beginners.
              YouTube Channel - Public HISE tutorials
              My Patreon - HISE tutorials

              DanHD ustkU 2 Replies Last reply Reply Quote 0
              • DanHD
                DanH @David 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 @David 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...

                    Hise made me an F5 dude, any other app just suffers...

                    David HealeyD 1 Reply Last reply Reply Quote 0
                    • David HealeyD
                      David Healey @ustk
                      last edited by

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

                      Free HISE Bootcamp Full Course for beginners.
                      YouTube Channel - Public HISE tutorials
                      My Patreon - HISE tutorials

                      ustkU 2 Replies Last reply Reply Quote 0
                      • ustkU
                        ustk @David Healey
                        last edited by

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

                        Hise made me an F5 dude, any other app just suffers...

                        1 Reply Last reply Reply Quote 0
                        • ustkU
                          ustk @David 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();
                          

                          Hise made me an F5 dude, any other app just suffers...

                          David HealeyD 1 Reply Last reply Reply Quote 1
                          • David HealeyD
                            David Healey @ustk
                            last edited by

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

                            Free HISE Bootcamp Full Course for beginners.
                            YouTube Channel - Public HISE tutorials
                            My Patreon - HISE tutorials

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

                            14

                            Online

                            2.2k

                            Users

                            13.3k

                            Topics

                            116.2k

                            Posts