So I have an inner loop situation with a buffer of floating point and integer values that are to be copied over to a another buffer in string format.
What are my alternatives to round and insert a thousand separator when formatting strings? Whatever the approach I end up using, it has to be flexible enough in permitting different formats. Also, because this is a inner loop scenario, I want to optimize any solution as far as possible.
It would seem locale.h
is one way to do it. But in that case, how can I setup customized locales, and how do I actually use them? Or is there a better alternative altogether? If this is a noob question please just point me in the right direction.
EDIT:
Here are a few examples to clarify:
1000
gives 1,000
(If I want to use ,
as thousand separator)
1000
gives 1 000
(If I want to use space
as thousand separator)
1000.123
gives 1,000.1
(If I want to round to one digit and use ,
as thousand separator)
0
gives `` (If I want to show zero as a blank string)
I am on a POSIX system btw...