Dear ladies and gentlemen,
Recently, I realised I faced a problem with default settings and specifically the rounding numbers ability.
When I let Processing count up the first sum using the float function, it doesn’t show of the real answer, which is 13.05. Even using the nf() function (for strings) I still can’t round it to its real answer.
I wonder, how do I fix that problem on my computer?
Thanks in advance!
The result you get is not too surprising, because the pre-processor does not know how to deal with the numbers (are they integer are they float). You need to give it a bit of help:-
println(nf(1/3.0f, 2, 10));
But even then the result is bit strange
Next time please insert code with </>. You’ll get more answers when people don’t have to type your code, instead of copying it from code section.
Calculation of b. Because you use only integer values calculations are done as integers and result zero is then stored to b as float. If you change the first line to
It’s a common practise to use explicit float value as divider.
Second problem comes from how floating point numbers are presented internally. They are not accurate, they can be slightly off like value of a 13.049999.