Data Types
Floating Point
double values store fractional numbers and are printed with floating-point formats.
Floating Point
floating_point.c
#include <stdio.h>
int main(void) {
double price = ;
double taxRate = 0.08;
double total = price + price * taxRate;
printf("price=%.2f\n", price);
printf("total=%.2f\n", total);
return 0;
}
#include <stdio.h>
int main(void) {
double price = ;
double taxRate = 0.08;
double total = price + price * taxRate;
printf("price=%.2f\n", price);
printf("total=%.2f\n", total);
return 0;
}
#include <stdio.h>
int main(void) {
double price = ;
double taxRate = 0.08;
double total = price + price * taxRate;
printf("price=%.2f\n", price);
printf("total=%.2f\n", total);
return 0;
}
double
`double` is the usual C type for fractional numeric work.
format
`%.2f` prints a floating-point value with two digits after the decimal point.