1

[Java] How to truncate a float correctly?

view story
linux-howto

http://ubuntuforums.org – I am by-in-large a python programmer, so I thought it would be a good idea to get some practice in a statically-typed language. I've been learning basic Java, so to test out what I've learned so far I decided to make the obvious joke and make a coffee-based class named Java. Har har har. My question has to do with this particular bit of code: Code: float pct = delta/capacity; int heatdelta = 180*pct; //int heatdelta = 180 * (delta/capacity); heat+=heatdelta; The basic idea is to calculate a percentage, then truncate the resulting float. If I use the above code, I get the following error: (Hardware)