I use the MPFR library to do calculations on big numbers, but also return a double with 8 digits after the decimal point.
I mpfr_sprintf the number to a char array so precision or anything isn't lost. Everything is fine except that I didn't find any thousand separator option in the documentation(or I missed it).
Given a number such as 20043.95381376 I would like to represent it like 20,043.95381376 for better readability.
Or the number 164992818.48075795 as 164,992,818.48075795
I read about an apostrophe that should be added to printf/sprintf, but that seems to be a UNIX/POSIX thing and I am a Windows user.
Since internally I print the number as a string, I thought what I could do is write a custom implementation that would automatically add the comma depending on the number(>1000>10000>100000 and so forth) but then I realized that functions like strncpy or strcpy will essentially replace, not add the comma to the desired position. And here is how I am back to square one on how to do it.
How can I do it?
strncpy
, its semantics are counter-intuitive and error-prone. – Tamalatamale