从双Java中拿走10%

时间:2017-04-10 23:22:53

标签: java double percentage

我想知道如何从Java的双倍价值中拿走10%的费用?我曾尝试研究Java中的百分比,但这有点让人困惑。

1 个答案:

答案 0 :(得分:0)

你可以乘以0.1而不是使用百分数。

例如:

/*Your starting value*/
int x = 100
/* Your percent you want to take away*/
int y = 0.1 /*0.1 is the same as 10%*/
int z = x*y
/* A takes your starting amount and takes away 10% */
int a = x-z
/* a is your answer */

更简单的方法是乘以0.9(乘以90%)。

/*Your starting number*/
int x = 100
/*What you want to take away*/
int y = 0.9
int z = x*y

这确实需要更少的代码和设备。