How to round floating point numbers to the nearest integer in C?

前端 未结 11 650
鱼传尺愫
鱼传尺愫 2020-12-16 04:03

Is there any way to round numbers in C?

I do not want to use ceil and floor. Is there any other alternative?

I came across this code snippet when I Googled f

11条回答
  •  时光说笑
    2020-12-16 04:48

    just add 0.5 to the number and typecast it.. and print it by type casting it in integer.. otherwise you can go with round() inside which just pass the argument as the respective number.

提交回复
热议问题