How to format a thousand separator in C with FreeBSD? I obtain the code from one of the answers here How can I format currency with commas in C? and it is working in my Ubuntu Linux system but not in my FreeBSD 11.4 and 14-CURRENT systems.
#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;
}
2
Answers
Just found this, by specifying this argument
en_US.UTF-8
in the setlocale() will also provide thousand separator in C with FreeBSD.The
printf
manpage(3) says:so, it uses the locale separator.
You can do something like that:
then compile like this:
which will output: