Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

money format and printing in columns

Status
Not open for further replies.

cathycena

Programmer
Jan 1, 2002
2
PH
How do you print in columns (as in like microsoft excel)?

How do you print your numbers in money format? Like with commas every after 3 digits (example: 1,000,000).

Thanks for all you help!:)
 
To print in columns you can use the "\t" escape code for tab. As far as inserting commas, I havn't worked in C for a while but this should work for thousands, you can use this as a base.

if (orig_num >= 999)
{
printf("$%d,%d", (orig_num / 1000), (orig_num - ((orig_num / 1000) * 1000)) );
} else {
printf("$%d", orig_num);
}

This doesn't use decimals, but it should be fairly easy to convert. I know this might not be the best way, but like I said, I'm a little out of practice, and this flu is getting to me ;)

Hope this helps,
Rob Rob
"Programming is like art...It makes me feel like chopping my ear off."

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top