开发者

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜