2017-04-10 41 views
0

我想知道如何從Java的雙重價值中獲得10%的收益?我嘗試過研究Java中的百分比,但它有點令人困惑。從雙Java取10%

+1

乘以0.9(即90%)? – Adam

回答

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(它由multiplys 90%)相乘的更簡單的方法。

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

這確實需要更少的代碼和eqations。

+0

爲什麼做三次計算就足夠了? – Roope

+0

我還沒有補充。 – card100

+1

我建議使用有意義的標識符而不是'x','y'和'z'。 –