下面的代碼在嘗試保存分數時會給出奇怪的結果(它會像if語句失敗一樣添加大量值)。當在if語句中進行比較時,超出範圍
double EndScore = (double)(mScoreManager.getScore());
if(mWorldCounterBox.getCurrentAlivePopulationPercent() < 97.0)
{
EndScore += (mWorldCounterBox.getCurrentAlivePopulationPercent()) * 100.00;
}
System.out.println(mWorldCounterBox.getCurrentAlivePopulationPercent()); //Output: 1.0544652507298142E-7
System.out.println(EndScore); //Output: 1.0000105446525074
//Increase score per dead %.
if(mWorldCounterBox.getCurrentAlivePopulationPercent() < 0.1)
{
EndScore += 20000.0;
}
System.out.println(EndScore); //Outout 20001.000010544652 -- WRONG HERE
SettingsSaveLoad.setCountryScore(mCurrentWorld, (float)(EndScore));
我不理解你的問題。 'mWorldCounterBox.getCurrentAlivePopulationPercent()'小於0.1,所以20000.0被添加到'EndScore'。 –
儲蓄分數在哪裏? – PeterMmm
EndScore的價值應該是什麼,順便說一句,您應該按照慣例重新命名爲endScore? – Djon