anonymous
  • anonymous
Hello, I am trying to write a java method for calculating total annual salary. The method receives monthlySalary and monthlySales. The commission is 2% of monthly sales. The output has to be an int rounded to the nearest dollar. I can't seem to get it working and output "1245" instead of "1244.63" Please help!
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
ankit042
  • ankit042
You can try using Math.round(number)
e.mccormick
  • e.mccormick
And you may need to type cast it to turn it into an int.
anonymous
  • anonymous
Thanks, I'll give it a try. I was type casting the double into an int before, but it was rounding to the nearest 1000, ie 12000 from 12120.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

e.mccormick
  • e.mccormick
The easy way it to have it return the cast of the rounded number. So it takes in the salary and sales, does the math, and returns a rounded number that is cast into an int.
e.mccormick
  • e.mccormick
``` public class RoundTest{ public static void main(String[] args){ double a = 12120.682; System.out.println("Just a: " + a); System.out.println("Int a: " + (int)a); System.out.println("Rounded a: " + Math.round(a)); System.out.println("Int of Rounded a: " + (int)Math.round(a)); } } ``` Got me: Just a: 12120.682 Int a: 12120 Rounded a: 12121 Int of Rounded a: 12121 The Rounded one might return an int, but by casting it after the rounding, you make sure it returns an int.

Looking for something else?

Not the answer you are looking for? Search for more explanations.