Printing a number in standard thousand format using printf
Hi,
Please see the C program below. #include <stdio.h> #include <stdlib.h> #include <locale.h> int main (int argc, char* argv[]) { setlocale (LC_ALL, ""); printf ("%'llu\n", strtoull("109488", (char**) NULL, 10)); return 0; } When it's compiled and run on a Redhat 6.6 Linux machine, the output is 109,488 When it's compiled and run on a Ubuntu 14.04.3 LTS machine, the output is 1,09,488 Could someone please tell how can I get the 1st output (109,488) on the second machine (Ubuntu) ? Thank you. |
Please use [code][/code] tags around your code
What happens when you use the same printf at the command line? Code:
$ printf "%'llu\n" 109488 |
Check if the LC_ALL variable is set on both machines. Check this out: https://wiki.archlinux.org/index.php/locale
|
Quote:
Somehow I found that if I add setlocale(LC_NUMERIC, "en_US.UTF-8"); to my C program, then it prints the number in desired thousand format. Thanks grail. |
Gald you found your solution :) Please remember to mark the question as SOLVED.
|
All times are GMT -5. The time now is 05:57 AM. |