【发布时间】:2014-08-04 03:25:32
【问题描述】:
我目前正在开发一款游戏,但遇到了一个小问题。 当玩家从商店购买物品时,我将其设置为以购买价格的 75% 出售。 但是当检查价值时(在出售物品之前),它会说,例如,“可以出售 115.0 金币” 如何从“115”中删除“.0”? 我还是编码新手,任何帮助表示赞赏。 (它也用括号显示,我也想删除它们。例如:“你可以卖这个(120.0)金币。”)
编辑:这是java。
int ShopValue = (int)Math.floor(getItemShopValue(removeId, 1, removeSlot));
String ShopAdd = "";
if (ShopValue >= 1000000000) {
ShopAdd = " (" + Math.floor(ShopValue*.75 / 1000000000) + " billion)";
} else if (ShopValue >= 1000000) {
ShopAdd = " (" + Math.floor(ShopValue*.75 / 1000000) + " million)";
} else if (ShopValue >= 1000) {
ShopAdd = " (" + Math.floor(ShopValue*.75 / 1000) + "k)";
} else if (ShopValue >= 100) {
ShopAdd = " (" + Math.floor(ShopValue*.75 / 1) + ")";
} else if (ShopValue >= 10) {
ShopAdd = " (" + Math.floor(ShopValue*.75 / 1) + ")";
}
c.sM(c.getItems().getItemName(removeId)+": shop will buy for <col=255>"+ShopAdd+"</col> coins");
}
}
【问题讨论】:
-
你用的是什么编程语言?
-
@aflasin 给你答案:Math.floor() 返回一个双精度值,将显示为整数,使用 ((int) Math.floor(..) )。