Reputation: 21
I have a problem, when I´m trying to multiply int by double. int are baseSalary and employeeSapary (this is int array) and commission is double constant = .09 I need to get employeeSalaries in int but keep getting a problem saying that i cant multiply int with double. I tried to convert double to int but in that case the eployeeSalary will always be baseSalary because commission will always be 0 (s*commission)=0 How can I get valid score for employeeSalaries? Thank you!
private int CalculateAndStoreSalary(int s, int i)
{
int.TryParse(txtSales.Text, out s);
employeeSalaries[i] = baseSalary + (s * commission);
return employeeSalaries[i];
}
Upvotes: 0
Views: 8349
Reputation: 50728
You can round it, and assign it as:
employeeSalaries[i] = Convert.ToInt32(Math.Round(baseSalary + (s * commission), 0));
It may not be exact, but something like that should do the trick, where you round it to the nearest zero (or use Floor or Ceiling to round down/up always), and then convert it to an integer on assignment.
Upvotes: 1