What does $ sign stands for ?

+1 kavil mehta · January 17, 2016
As  I saw an example in tutorial 25, in a printf statement, the dollar sign was used. What does it stand for ?

printf(" Day: %d /t Amount : $ .2%f \n", day, amount);

Post a Reply

Replies

Oldest  Newest  Rating
0 Linguist Llama · January 18, 2016
You appear to have misplaced the % character in ".2%f". I think you meant "%.2f". Note that I'm not referring to the dollar character ($); I'm referring to the percent symbol.

The dollar character is meaningless in C. In fact, it's not even in the C standard. If it's possible that your code might execute on machines that don't have this character, you should probably find a different symbol...

In fact, it'd probably be a good idea to just use the currency symbol you're referring to as it appears in the stock market. For example, your printf statement should probably look like this, if you're talking about US dollars:

printf(" Day: %d /t Amount : %.2f USD\n", day, amount);

... or if you want to continue to use the $ sign:

printf(" Day: %d /t Amount : $ %.2f \n", day, amount);

P.S. It's unusual to use float or double for currencies due to rounding errors.
0 Laura Lee · January 17, 2016
You are confusing % with $.
  • 1

C

126,554 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator