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 for the answer:
(int)(num < 0 ? (num - 0.5) : (num + 0.5))
The above line always prints the value as 4 even when float num =4.9.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…