First let me say that I am fully aware of the number_format() function. However...

I need to use sprintf() function to format numbers with commas for the thousands separators. I cannot use number_format() for a very specific reason.

Please, anyone who knows the correct argument to pass to sprintf() to format the numbers with commas let me know.

Thanks.

    sprintf() doesn't do that, so no matter what arguments you pass to it, it won't work. Why can't you use number_format()?

    If you can't use number_format(), then make your own function that puts in the commas...

    Diego

      There isn't one, I'm afraid.

      What's the very specific reason? You've got me all curious now...

        The reason I can't (don't want to) use number_format or write my own is because I'm using the jpGraph, graphics library and I don't want to modify it. The library uses the sprintf function to format numbers.

        Are you sure sprintf won't do that? I'm not.

          Even if sprintf() is able to add commas, how can you change the parameters if you don't want to modify the library? Anyway you do it you'll have to modify the library.

          You can make a backup of the library, add number_format() or your own function and test it. If it doesn't work, restore the backup and that's it.

          Diego

            I don't want to modify it because of certain standards we have about 'exceptions and modifications'.

            Anyway, here's an example:

            $bplot->SetValueFormat(" $ %d",70);

            The first argument is the format, in this case formatted with a dollar $ sign and no decimals. So as you can see, I can pass any argument here without modifying the library.

              Then you can do this:

              $bplot->SetValueFormat(" $ %s", number_format(70));

              Diego

                Write a Reply...