This content has been marked as final. Show 5 replies
You can cast number3 into an int
But in either case, you're going to lose some data.
answer = number * number2 * (int)number3;
Losing data, I mean 1.5 will become 1.
I'm not sure if that answered your question.
Were you expecting 4.5 as the outcome?
If so, then just change answer to a double type.
Message was edited by:
I guess what I want is the answer rounded to an int. For example the math equation gives you something like 1+3*1.5=5.5, however I want it to round it to 6.
This is the method you'll need then:
It rounds a double type into an a long.
You'll then cast that into an int.
The variable "answer" now contains the number 6.
answer = num1 * num2 * (int)Math.round(num3);
Safer bet is to round the result.
answer = (int)Math.round(num1 * num2 * num3);
Thanks Flounder that's exactly what I needed. I actually had tried the Math.round but didn't figure out the (int) part which of course didn't make it work.