c - Can't round number to two decimal places using floorf -
i found formula here:
podrucje[i][j] = floorf(podrucje[i][j] * 100 + 0.5)/100;
where podrucje[][]
float matrix. floorf
returns correct value (desired * 100
) problem /100
. example if have 49.599998
, floorf
returns 4960.000
, after dividing 100
result again 49.599998
.
where problem?
i know can round while printing i'm going use matrix in excel converted range can't influence on representation.
most decimal numbers aren't representable floats.
you need either store them integers, or rounding when converting humanly visible (i.e. printing number out).
if want use number further calculations , need rounded first, use different representation.
Comments
Post a Comment