我使用下面的代碼在我的活動之一來填充微調...奇怪雙到字符串的轉換
for(double i = 0; i < 10 ; i+=0.1) {
rVoltsList.add(Double.toString(i));
}
Spinner rVoltsSpinner = (Spinner) findViewById(R.id.recloseVoltsSpinner);
ArrayAdapter<String> rVoltsAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, rVoltsList);
rVoltsSpinner.setAdapter(rVoltsAdapter);
我是假設這會給我一個名單如下:0.0,0.1 ,0.2,0.3,0.4等等。 然而,這是列表中的樣子,當我運行我的程序:
0.0
0.1
0.2
0.30000000000000000000000004
0.4
0.5
0.6
0.7
0.79999999999999999999
0.89999999999999999999
0.99999999999999999999
1.09999999999999999999
1.2
1.3
and this goes on until 9.99999999999999999998
什麼想法?
[在上一個雙運動小數]的可能重複(http://stackoverflow.com/questions/4937402/moving-decimal-places-over-in-a -double) – assylias