Jump to content

Java Calculation Isn't Working

Rheinwasser
Go to solution Solved by fizzlesticks,

Is width an integer? Try casting it to a float/double.

In java, if you do an operation with integers, it will give you an integer. 7 / 2 = 3 for example.
If you want it to give you a double, you should do the operation with doubles, 7.0 / 2.0 = 3.5.

Doing an operation with an integer and a double will give you a double 7 / 2.0 = 3.5 and 7.0 / 2 = 3.5

Link to comment
Share on other sites

Link to post
Share on other sites

  • 1 year later...

I think that you have a casting issue.

I suggest to take a look at this java casting course to understand better the concept.

I hope that this will help.
 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×