Не удается неявно преобразовать тип float в int - C#
Формулировка задачи:
Листинг программы
- private void Awake()
- {
- if (PlayerPrefs.HasKey("SV"))
- {
- float totalBonusPS = 0 ;
- sv = JsonUtility.FromJson<Save>(PlayerPrefs.GetString("SV"));
- score = sv.score;
- for (int i = 0; i < shopItems.Count; i++)
- {
- shopItems[i].levelOfItem = sv.levelOfItem[i];
- shopItems[i].bonusCounter = sv.bonusCounter[i];
- if (shopItems[i].needCostMultiplier) shopItems[i].cost *= (int)Mathf.Pow(shopItems[i].costMultiplier, shopItems[i].levelOfItem);
- if (shopItems[i].bonusIncrease != 0) scoreIncrease += (int)Mathf.Pow(shopItems[i].bonusIncrease, shopItems[i].levelOfItem);
- totalBonusPS += shopItems [i].bonusPerSec * shopItems [i].bonusCounter;
- }
- DateTime dt = new DateTime (sv.date[0],sv.date[1],sv.date[2],sv.date[3],sv.date[4],sv.date[5]);
- TimeSpan ts = DateTime.Now - dt;
- float offlineBonus = (float)ts.TotalSeconds * totalBonusPS;
- score += offlineBonus ;
- print("Вы отсутствовали: " + ts.Days + "Д. " + ts.Hours + "Ч. " + ts.Minutes + "М. " + ts.Seconds + "S.");
- print ("Вы заработали " + offlineBonus + "$");
- }
- }
Решение задачи: «Не удается неявно преобразовать тип float в int»
textual
Листинг программы
- float a = 0.0;
- int b = Convert.ToInt32(a);
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д