Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How can I format currency with commas in C?
- #include <stdio.h>
- #include <locale.h>
- int main(void)
- {
- setlocale(LC_NUMERIC, "");
- printf("$%'.2Lfn", 123456789.00L);
- printf("$%'.2Lfn", 1234.56L);
- printf("$%'.2Lfn", 123.45L);
- return 0;
- }
- > make example
- clang -Wall -Wextra -Werror example.c -o example
- > ./example
- $123,456,789.00
- $1,234.56
- $123.45
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement