#Calculation in Wrong Format

18 messages · Page 1 of 1 (latest)

fast forge
#

For some reason, whenever I try to do a float calculation (with a float variable), it casts the final answer to int then right back to double. Can anyone help?

blissful hollowBOT
#

This post has been reserved for your question.

Hey @fast forge! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

torn nexus
#

can you show the calculation ?

fast forge
#

bmi = (int)(bmi*10) / 10;

#

bmi itself is already a double.

#

@torn nexus

torn nexus
#

You want to cast to int or 5o double ?

fast forge
#

I don't want it to cast at all.

#

Oh, shoot, I sent the wrong thing.

#

mHeight = (int)(mHeight*10) / 10;

#

Specifically, double mHeight = (int)(mHeight*10) / 10;

#

I want to round it to the tenths.

#

Shoot, should I have made the bottom number a double?

#

*denominator

torn nexus
#

Yeah so Math.round((mHeight*10)/10f)

fast forge
#

Oh, right, forgot Math.round existed.

#

I'm so stupid. Thanks!