If I have a value of 19750, and I know that is an implied decimal of 3 spaces ie. 19.750, how do I format to appear like that. I can substr all day long, but if there is a number_format or sprintf way to do this, that would be awesome

any help would be great

    If I have a value of 19750, and I know that is an implied decimal of 3 spaces ie. 19.750, how do I format to appear like that. I can substr all day long, but if there is a number_format or sprintf way to do this, that would be awesome

    any help would be great

      chrisleon wrote:

      if there is a number_format or sprintf way to do this, that would be awesome

      Have you considered dividing by 1000 first?

        I won't claim this is the "best" way, but it's probably what I'd do if it's just an output issue:

        printf ("The value is %.3f", $value / 1000);
        

        If you want to assign it to a variable, it might be more efficient to do:

        $var = round($value / 1000, 3); // makes sure there is no floating point precision problem
        

          Cross-posted threads merged. :glare:

            Write a Reply...