这是我的代码。我收到错误
调用在以下方法或属性之间不明确:
System.Math.Round(double, int)
和System.Math.Round(decimal, int)
我知道这是由于操作的结果在双精度和小数之间模棱两可,但我不知道如何只获得小数作为结果。
int enemiesThisWave= Decimal.ToInt32(Math.Round(TotalEnemies * (percentForWave / 100), 1));
int enemiesForType = Decimal.ToInt32(Math.Round(lenghtList * (percentForType / 100), 1));
执行此操作的一种简单方法是将其中一个值强制转换为要调用的类型:
int enemiesThisWave = Decimal.ToInt32(Math.Round(TotalEnemies * ((decimal)percentForWave / 100), 1));
或在100
值上指定小数:
int enemiesThisWave = Decimal.ToInt32(Math.Round(TotalEnemies * (percentForWave / 100m), 1));
假设TotalEnemies
和percentForWave
是int
改用Mathf.FloorToInt
:
int enemiesThisWave= Mathf.FloorToInt(TotalEnemies * percentForWave / 100f + 0.5f);
int enemiesForType = Mathf.FloorToInt(lenghtList * percentForType / 100f + 0.5f);