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

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -