C decimal places
To specify the number of decimal places in C, you can use the printf
function along with the appropriate format specifier. The format specifier for decimal places is %f
for floating-point numbers and %lf
for double precision floating-point numbers. Here's an example:
#include <stdio.h>
int main() {
double num = 3.14159;
// Print with 2 decimal places
printf("%.2lf\n", num);
return 0;
}
This will output 3.14
. You can change the number inside the format specifier to specify the desired number of decimal places.