Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4577084
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:17:48+00:00 2026-05-21T20:17:48+00:00

How do do a thousand separator (like a comma) in a printf ? example:

  • 0

How do do a thousand separator (like a comma) in a printf?

example:

printf("<td class='number'>%d</td>", $totals['Sold']); //need thousand separated 
printf("<td class='number'>%.2f</td>", $totals['Fees']); //need thousand separated

UPDATE this is what i had originally:

foreach(array_keys($totals) as $key){
        if(is_numeric($totals[$key])){
            $totals[$key] = number_format($totals[$key],2);
        }
    }

    echo "</tbody>
        <tfoot><tr>";
    echo "<td class='text' colspan='4'>Totals:</td>";
    echo "<td class='number'>{$totals['Bought']}</td>";
    echo "<td class='number'>{$totals['Sold']}</td>";
    echo "<td class='number'>{$totals['Fees']}</td>";
    echo "<td class='number'>{$totals['Realized']}</td>";
    echo "<td class='number'>{$totals['Net']}</td>";
    echo "<td colspan='3'>{$totals['EOD Price']}</td>";
    echo "</tr>
        </tfoot>";

and I want it to be come something like:

echo "</tbody>
        <tfoot><tr>";
    echo "<td class='text' colspan='3'>Totals:</td>";
    printf("<td class='number'>%d</td>", $totals['Bought']) ;
    printf("<td class='number'>%d</td>", $totals['Sold']) ;
    printf("<td class='number'>%.2f</td>", $totals['Fees']) ;
    printf("<td class='number'>%.2f</td>", $totals['Realized']) ;
    printf("<td class='number'>%.2f</td>", $totals['Net']) ;
    printf("<td colspan='3'>%.2f</td>", $totals['EOD Price']) ;
    echo "</tr>
        </tfoot>";

But I need the commas

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T20:17:49+00:00Added an answer on May 21, 2026 at 8:17 pm

    Make your code pretty and don’t echo it all. Just break out of PHP context to do it, and then instead of printf just echo using number_format:

    </tbody>
    <tfoot>
        <tr>
            <td ...>Totals</td>
            <td ...><?php echo number_format($totals['Bought'], 0); ?></td>
            <td ...><?php echo number_format($totals['Sold'], 0); ?></td>
            <td ...><?php echo number_format($totals['Fees'], 2); ?></td>
            ...
        </tr>
    </tfoot>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've looked this up a thousand times, and I always forget it, so, here
I have some lines in a CSV file like this: 1000001234,Account Name,0,0,3,711.32,0,0,18,629.64,22,340.96,COD,20,000.00,Some string,Some string
I'm trying not to use the ',' char as a thousand separator when displaying
I have a label that i want to show it's Text(1234567) Like A Number
I have a GWT project in which I need to manually specify currency, number
I have a mobile WEB Page showing a bank statement. Something like this: DATE
I need to analyze a few thousand XML documents to see if some of
In an international web app, we deal with currencies like this: USD: 2,400.55 EUR:
Although several thousand Emacs Lisp libraries exist, GNU Emacs, until version 24.1 did not
I know I'll get a thousand Depends on what you're trying to do answers,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.