我正在进行一个项目,目前遇到了如下错误:
无法将类型“float”隐式转换为“int”。
我有一定的理解,只是需要帮助将我的浮点数转换为整型。
这只是其中一个浮点数的例子:
float key = 0.5f;
int key = 53;
这是具体的代码部分:
// price in scrap, e.g. 29 / 9 = 3.33 ref
static int BuyPricePerTOD = 21;
// price in scrap, e.g. 31 / 9 = 3.55 ref
static float SellPricePerTOD = BuyPricePerTOD + 0.5F;
static int BuyPricePerKey = 53;
static float SellPricePerKey = BuyPricePerKey + 0.5F;
static int TimerInterval = 170000;
static int InviteTimerInterval = 2000;
int UserWeapAdded,UserScrapAdded,UserRecAdded,UserRefAdded,
UserKeysAdded,UserTODAdded,BotTODsAdded,BotKeysAdded,
BotScrapAdded,BotRecAdded,BotRefAdded,InventoryMetal,
InventoryScrap,InventoryRec,InventoryRef,InventoryKeys,
InventoryTOD,PreviousTODs,PreviousKeys,WhileLoop,InvalidItem = 0;
float UserMetalAdded, BotMetalAdded, OverpayNumKeys,
OverpayNumTOD, ExcessInScrapKey, ExcessInScrapTOD = 0.0F;
double ExcessRefinedKey, ExcessRefinedTOD = 0.0;
1.8
四舍五入后是2
,但截断后是1
。 - Matt Burlandint
类型无法存储小数值,因此被称为整数。 - pcnThird