-
format number
hi everyone,
i have a simple question because i'm a newbie in c programming. i need to format a double to a currency like number : something like 11.00. How can I do this?
also, i'm trying to print a double to the screen but it's not displaying correctly. here is my code:
printf ("sInt = %lf\n", &sInt); //this always display 0.0000000 instead of the correct number.
Thanks a lot
-
Why are you trying to print it's address as a float? Do not use & when using printf.
Quzah.
-
Yes, in the function printf, you pass by value, not reference (&). You need not to change the variable just work with the value.
-
This would be one of the first things in just about all tutorials and most books that you would learn. Check out a few tutorial sites, It really helps.
-
Here's an example of rounding to two decimal places.
double d = 1.23456789;
//either
printf("%.2lf\n",d);
//or this
printf("%5.2lf\n",d);