【发布时间】:2017-01-13 13:23:20
【问题描述】:
请检查以下安卓代码
private void preMealChartCreator(int numberOfPreMealLow, int numberOfPreMealNormal, int numberOfPreMealHigh, int totalReadings) {
Log.d("OverViewFragment","chart_low: "+numberOfPreMealLow+" chart_normalssss: "+numberOfPreMealNormal+" chart_high: "+numberOfPreMealHigh+" chart_total: "+totalReadings);
int preMealLowPercentage = (int)((numberOfPreMealLow/totalReadings)*100);
double preMealNormalPercentage = (double)((numberOfPreMealNormal/totalReadings)*100);
int preMealHighPercentage = (int)((numberOfPreMealHigh/totalReadings)*100);
Log.d("OverViewFragment","chart_low: "+"low_percentage: "+preMealLowPercentage+" normal_percentage: "+preMealNormalPercentage+ "high_percentage: "+preMealHighPercentage);
Log.d("OverViewFragment","chart_low: "+ " chart_normalssss: "+numberOfPreMealNormal+ " chart_total: " +totalReadings+" normal_manual: "+ (1/5)*100);
lowBarView.set(Color.GRAY, preMealLowPercentage);
normalBarView.set(Color.GREEN, (int)preMealNormalPercentage);
highBarView.set(Color.YELLOW, preMealHighPercentage);
verHighBarView.set(Color.RED, 6);
lowTextView.setText(getPercentage(preMealLowPercentage));
normalTextView.setText(getPercentage((int)preMealNormalPercentage));
highTextView.setText(getPercentage(preMealHighPercentage));
veryHighTextView.setText(getPercentage(6));
}
无论我做什么,我的百分比总是0。我想检查一下是null还是0,所以我打印了日志,一切正常。日志如下
01-13 18:50:08.647 9232-9232/xx.com.au.xxD/OverViewFragment: chart_low: 0 chart_normalssss: 1 chart_high: 2 chart_total: 5
01-13 18:50:08.647 9232-9232/xx.com.au.xxD/OverViewFragment: chart_low: low_percentage: 0 normal_percentage: 0.0high_percentage: 0
01-13 18:50:08.647 9232-9232/xx.com.au.xxD/OverViewFragment: chart_low: chart_normalssss: 1 chart_total: 5 normal_manual: 0
我什至尝试手动转换为double,然后硬编码值,但没有任何效果。这里有什么问题?
【问题讨论】:
标签: java android math double integer-division