Advertisement
Guest User

Untitled

a guest
Aug 8th, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. How can I format currency with commas in C?
  2. #include <stdio.h>
  3. #include <locale.h>
  4.  
  5. int main(void)
  6. {
  7. setlocale(LC_NUMERIC, "");
  8. printf("$%'.2Lfn", 123456789.00L);
  9. printf("$%'.2Lfn", 1234.56L);
  10. printf("$%'.2Lfn", 123.45L);
  11. return 0;
  12. }
  13.  
  14. > make example
  15. clang -Wall -Wextra -Werror example.c -o example
  16. > ./example
  17. $123,456,789.00
  18. $1,234.56
  19. $123.45
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement