Reputation: 68
This is my code. I'm getting the error
The call is ambiguous between the following methods or properties:
System.Math.Round(double, int)
andSystem.Math.Round(decimal, int)
I know this is due to the result of the operation being ambiguous between a double and a decimal, but I have no clue on how to get only a decimal as a result.
int enemiesThisWave= Decimal.ToInt32(Math.Round(TotalEnemies * (percentForWave / 100), 1));
int enemiesForType = Decimal.ToInt32(Math.Round(lenghtList * (percentForType / 100), 1));
Upvotes: 0
Views: 1927
Reputation: 20249
Use Mathf.FloorToInt
instead:
int enemiesThisWave= Mathf.FloorToInt(TotalEnemies * percentForWave / 100f + 0.5f);
int enemiesForType = Mathf.FloorToInt(lenghtList * percentForType / 100f + 0.5f);
Upvotes: 1
Reputation: 7091
One simple way to do this is to cast one of your values to the type you want to invoke:
int enemiesThisWave = Decimal.ToInt32(Math.Round(TotalEnemies * ((decimal)percentForWave / 100), 1));
or specify decimal on your 100
value:
int enemiesThisWave = Decimal.ToInt32(Math.Round(TotalEnemies * (percentForWave / 100m), 1));
Assuming TotalEnemies
and percentForWave
are int
Upvotes: 4