0

坚持如何执行一个简单的行公式,如下所示:

double profit=0;
double totalPrice=19.25;
int cost = 12;

profit = totalPrice - 2.15(totalPrice * 15 %) - (cost);

我怎样才能在代码中写出上面的等式,在它给出错误之前我从来没有这样做过2.15and 15%。我如何表示这些数字?

谢谢

4

2 回答 2

3
profit = totalPrice - (2.15 * (totalPrice * .15)) - cost;
于 2013-09-05T23:34:21.590 回答
3
profit = totalPrice - 2.15 * (totalPrice * 0.15) - (cost);

15% 表示为 0.15。

于 2013-09-05T23:40:01.240 回答