How to get float value with two decimal values in C language?
i like to get float value 开发者_开发知识库with first two decimal value in C language.
my input is
Float f;
f=2.3678;
i like to get output like this
2.36
Include the math.h
header file and do this:
float f;
f = 2.3678;
f = floor(f * 100) / 100;
// f = 2.36
printf("%.2f", 2.3678); /* prints 2.37 */
Try this:
f=f*100;
f=(int)f;
f=f/100;
精彩评论