double - Round of a negative decimal in C -
i need round of decimal numbers precision in c program. facing difficulties in these type of examples
x = -0.000000001235
which when rounded (using %.5f
) 5 decimals prints -0.00000
.
how should remove negative sign?
if number greater -0.000005 round absolute value. can knock 1 on head simple ternary.
if want compare numbers tolerance of 5th decimal place use fabs(a - b) < 0.00001
test equality. don't understand why you'd ever want round numbers explicitly, let alone %.5f
comes in.
Comments
Post a Comment