# Thread: converting floating point number to a currency display

1. ## converting floating point number to a currency display

So im trying to generate a program that will take a floating point number and have the output display it as a currency, example:

input 34534.3675
output \$34,534.37

input 99.1
output \$99.10

input 2030
output \$2,030.00

Any help on what algorithms I should have in my function aruguments ?

2. You can do all that using simple printf format strings

3. Well, no. Comma separation every 3 digits is not built into standard formatting.

4. You can do all that using simple printf format strings
However the flags are an extension of the standard and documentation is difficult to come by.

In order to use the thousands separator flag, which is a single-quote ( ' ) you have to set the locale. C has its own default locale but it contains no thousands separator. The easiest way to go about setting the locale is to let the function figure out which one to use:
Code:
```#include <locale.h>
...

setlocale(LC_ALL, "");```
After that the thousands separator will work (and it will be correctly based on the user's language settings, too!).

As for the decimal, that's done with the "." modifier - that's part of the standard and is pretty well documented if you aren't already familiar with it.
And the dollar sign can just be before the formatting part for the number. If you want to be agnostic you can make a call to localeconv() and find out what the local currency sign is.

So, the general purpose printing function is this:
Code:
```#include <locale.h>
#include <stdio.h>
...

struct lconv *locale;

setlocale(LC_ALL,"");
locale = localeconv();

float value = 1234.567;

printf("%s%'.2f\n", locale->currency_symbol, value);```
I'm feeling very generous today, I guess.

5. You'll want to use locales for this. Look into the functions in <local.h>

EDIT: Nevermind, nice post above