Forum

    • Register
    • Login
    • Search
    • Categories

    doubleToString 0 digit...

    Bug Reports
    2
    3
    59
    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.
    • ustk
      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)

      Tired to press F5 in the forum...
      Studio427 Audio - Audio Instruments & FX Plugins for music production. Website - Facebook

      1 Reply Last reply Reply Quote 0
      • Christoph Hart
        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));
        
        ustk 1 Reply Last reply Reply Quote 1
        • ustk
          ustk @Christoph Hart last edited by

          @Christoph-Hart Wow cool! Thanks 👍

          Tired to press F5 in the forum...
          Studio427 Audio - Audio Instruments & FX Plugins for music production. Website - Facebook

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

          20
          Online

          803
          Users

          5.5k
          Topics

          51.8k
          Posts