Jump to content

Java Calculation Isn't Working

Go to solution Solved by fizzlesticks,

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

double speed = 1-((1/width)/100); 

why doesnt this work?

speed is equals 1.0 for some reason when it should be 0.996.

it's really weird, if i divide through 10 it's 3.0.

 

i hope somebody can help.

thanks!

Link to comment
https://linustechtips.com/topic/255216-java-calculation-isnt-working/
Share on other sites

Link to post
Share on other sites

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

yes, it is.

casting didnt work, i initialized it as a double, now it works!

thanks  :)

Link to post
Share on other sites

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 post
Share on other sites

  • 1 year later...

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

×