嘿傢伙我有問題,使雙數的percentege。使十進制數的百分比
double pom = cumulativeProbability(GetZ(baby));
Log.d("Pom","" + pom);
double pom1 = round(cumulativeProbability(GetZ(baby)),2);
Log.d("Pom1", "" + pom1);
double pom2 = pom1 * 100;
Log.d("Pom2: ", "" + pom2);
下面是日誌:
06-05 02:30:04.574 13208-13208/com.bojan.readfromcsv D/Pom﹕ 0.5821510290598115
06-05 02:30:04.584 13208-13208/com.bojan.readfromcsv D/Pom1﹕ 0.58
06-05 02:30:04.584 13208-13208/com.bojan.readfromcsv D/Pom2:﹕ 57.99999999999999
我想這個給定的POM值四捨五入到小數點後兩位,而我得到這輪功能:
public static double round(double value, int places) {
if (places < 0) throw new IllegalArgumentException();
BigDecimal bd = new BigDecimal(value);
bd = bd.setScale(places, RoundingMode.HALF_UP);
return bd.doubleValue();
}
對於最後的結果pom2我想擁有58%.... Tnx
任何原因,你是通過地方寧願圓,而不是僅僅使用Math.round(pom2) ?? –
圍繞你的最後(pom2)雙。 – hungryghost