HISE Logo Forum
    • Categories
    • Register
    • Login

    doubleToString 0 digit...

    Scheduled Pinned Locked Moved Bug Reports
    3 Posts 2 Posters 197 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.
    • ustkU
      ustk
      last edited by

      Engine.doubleToString(value, 0) doesn't throw a 0 digit string, but 2 digits oscillating with 0 digit...

      I know I can use round but it's not practical in my situation. I have a function that needs a different number of digit depending on the value & unit to display. Some need 1, other 0, and other 2 digits Engine.doubleToString(value, object.digit)

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

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

        Yes, passing 0 as second argument means "give me all digits that are available" (actually I am just forwarding this to a JUCE helper method).

        But you can easily write a version that's more suitable for you like this:

        namespace GregsEngine
        {
            inline function doubleToString(value, numDigits)
            {
                if(numDigits == 0)
                    return "" + parseInt(value);
                else
                    return Engine.doubleToString(value, numDigits);
            }
        }
        
        // client code
        
        Console.print(GregsEngine.doubleToString(2412.0125, 0));
        Console.print(GregsEngine.doubleToString(2412.0125, 2));
        
        ustkU 1 Reply Last reply Reply Quote 1
        • ustkU
          ustk @Christoph Hart
          last edited by

          @Christoph-Hart Wow cool! Thanks 👍

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

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

          49

          Online

          1.7k

          Users

          11.7k

          Topics

          101.8k

          Posts