HISE Logo Forum
    • Categories
    • Register
    • Login

    Display Value Rounding

    Scheduled Pinned Locked Moved General Questions
    labeldisplay valuescripting
    8 Posts 3 Posters 413 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.
    • trillbillyT
      trillbilly
      last edited by

      Hey Gang,

      I've created custom labels to display knob values. When the knob stepSize is set to 1.0, all works well. But when stepSize is set to 0.1 or 0.01, the decimal displays an endless amount of numbers (2.984057975... for example). How do I stop/round the decimal at say tenths (0.01) instead of displaying the full amount?

      Here is the simple code I used to display the values.

      const var EQGainknb1 = Content.getComponent("EQGainknb1");
      const var Label1 = Content.getComponent("Label1");
      
      inline function onEQGainknb1Control(component, value)
      {
      	Label1.set("text", EQGainknb1.getValue());
      };
      
      Content.getComponent("EQGainknb1").setControlCallback(onEQGainknb1Control);
      
      NatanN Dan KorneffD 2 Replies Last reply Reply Quote 0
      • NatanN
        Natan @trillbilly
        last edited by

        @trillbilly Here you go
        Math.round() will do the job :)

        Label1.set("text", Math.round(EQGainknb1.getValue()));
        
        1 Reply Last reply Reply Quote 1
        • Dan KorneffD
          Dan Korneff @trillbilly
          last edited by

          @trillbill You can use Engine.doubleToString() to limit the number of decimal places.

          Engine.doubleToString(EQGainknb1.getValue(), 2);

          Dan Korneff - Producer / Mixer / Audio Nerd

          trillbillyT 1 Reply Last reply Reply Quote 2
          • trillbillyT
            trillbilly @Dan Korneff
            last edited by

            @Dan-Korneff Do I implement this directly in the callback?

            @Natan This works great except it rounds to the nearest whole number it seems. Can I make it round the nearest tenth?

            Dan KorneffD NatanN 2 Replies Last reply Reply Quote 0
            • Dan KorneffD
              Dan Korneff @trillbilly
              last edited by

              @trillbilly

              Label1.set("text", Engine.doubleToString(EQGainknb1.getValue(), 2));
              

              Dan Korneff - Producer / Mixer / Audio Nerd

              trillbillyT 1 Reply Last reply Reply Quote 3
              • trillbillyT
                trillbilly @Dan Korneff
                last edited by

                @Dan-Korneff Ya, my mistake, I tried this at first with no luck but made an error. This is it. Thanks!

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

                  @trillbilly Yeah, The One dan Supplied is the Answer,
                  Exactly, Just replace with one you posted above:

                  const var EQGainknb1 = Content.getComponent("EQGainknb1");
                  const var Label1 = Content.getComponent("Label1");
                  
                  inline function onEQGainknb1Control(component, value)
                  {
                  	Label1.set("text",Engine.doubleToString(EQGainknb1.getValue(), 2)); // Play with this to add more digits
                  };
                  
                  Content.getComponent("EQGainknb1").setControlCallback(onEQGainknb1Control);
                  
                  HiseSnippet 975.3ocsV0saaaCElxwbqVctXEnO.D4JafTW4z+FPvPciiSgwRR8lxB1tpiVj1lHTjBRTswsnOHauI8t7.zGl9FrcnjrkxpRWpAl7M97K+NGcNeTSh0A7jDcLxo0oKi3HmuC6uTYVLbAUnPiO.4bG7wzDCOljqZ+kQzjDNC43r0KrJbZ0Dk87omsOURUA7RUHzYZQ.+HQnvTpcxfeRHkGRY7SEgU79QCFGnUC0RcJfmsvdnHZv4z47SnV2ZfQNeyHlvni8MTCOA7YeMao+B8aT49elHQLUxsB8Q9PhxUiFtPHYSVUqIHjSyIkU9V4U98vGKXh05K6.eelARYDU6ANMtJjZdEH0+5fzgZIylfqAdNUfWyb3cWrePrHxTZwhsaiGqfWNynPauJrx8E0vqAdnF7PY5EROmeXLHrNhNOwyaGxi875tWa27evKfDC40zXxne1958b0z9jejrJGy4lg5vHsBD5rcoKaayPYrGQmxkWeb4l2N+TEJoPwIyRUAFgVQzpxzZCOVK6DrJ1cfzKS4ca69t1tsxySuDNjSC+By16LRMGRVOlNE54mp8MwB07NkIzBjyrYnS2cH61s6djG7.xDIcI4MByBhYgHgXzDJiQB0wbBSLWXRZ699Ln9e2ErXo.zCoR4TX9sSMET28pTtmnM7Wp5z08ctsbeuK4eaZ1rZsUjJIOtVy1Uq3uTfcTogS4wq5nqbDl2t5.8suYCzA48lJNpUiUByKi3Exki7Va4U8Jqdn0EaUUk0XUsYkVMtUp5y2nPEu6r6VEtCtZx1rtSwlkuTv3wHAyxBV9NCk0fJnot7iGs2knec7ATCcUtfzBGUDO1HrMLmC3uFH8x2ZagOfmbtQGA7WqmYPNt2rS9BjC14X3XWZ+yag+DpYEYMP.C+nvpLv+9kgzKpHN.3si7EuMC7+0eZe9vyRRmMSXSLlv1Ghmwj7I5Dgc5nL1cuDUAt3b31t.tY6cYn8V37cPTki8rAKWK7GhA1ESjy2hu+tOs2CAx+OiXCnW0rTI0bUNWaSnvfEYUI2rDXJ.wKqd4yWAQrWsDw8qar4FB26hmHLAKpGuMpAuvry+23s3Zs13QylwCLkfsI9veaSuC6q.J+hN0.ruGSARX671Iog9vM6Ab.IJEWlXmoaXWMyk8rx1NiOWwxD9a3ovXeqrSgw9qLhBoAw5WEjuPau37VYZ.Lox9lgVvGu.xj0KwXrWOO6Tu3UAA1Vw8ArWeL6tAw7vMHlGsAw73MHlmrAw7zMHle3KFi8SoddpQGlul.JlLJiL0wYjhBSYYSjn+APLNVdw
                  
                  trillbillyT 1 Reply Last reply Reply Quote 1
                  • trillbillyT
                    trillbilly @Natan
                    last edited by

                    @Natan Thanks! I got it, I was just blanking for a bit.

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

                    45

                    Online

                    1.7k

                    Users

                    11.7k

                    Topics

                    101.9k

                    Posts