Skip to content

Commit

Permalink
format numbers in the introductions
Browse files Browse the repository at this point in the history
  • Loading branch information
MoXtar-1s committed May 30, 2020
1 parent 925cbb3 commit 473427f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.moxtar_1s.android.disease_charts.china.province.ChinaProvinceDrawer;
import com.moxtar_1s.android.disease_charts.china.trend.ChinaTrendBean;
import com.moxtar_1s.android.disease_charts.china.trend.ChinaTrendDrawer;
import com.moxtar_1s.android.disease_charts.utils.NumberUtil;
import com.moxtar_1s.android.disease_charts.utils.SortUtil;
import com.moxtar_1s.android.disease_charts.utils.DateUtil;

Expand Down Expand Up @@ -133,11 +134,11 @@ private void loadChinaIntroBean() {

private String format(int cases, int increase) {
if (increase > 0) {
return cases + "\n+" + increase;
} else if (increase == 0) {
return cases + "\n--";
return NumberUtil.formatNumber(cases) + "\n+" + NumberUtil.formatNumber(increase);
} else if (increase < 0) {
return NumberUtil.formatNumber(cases) + "\n" + NumberUtil.formatNumber(increase);
} else {
return cases + "\n" + increase;
return NumberUtil.formatNumber(cases) + "\n--";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.moxtar_1s.android.disease_charts.global.country.GlobalCountryBean;
import com.moxtar_1s.android.disease_charts.global.distribution.GlobalDistributionBean;
import com.moxtar_1s.android.disease_charts.global.introduction.GlobalIntroBean;
import com.moxtar_1s.android.disease_charts.utils.NumberUtil;
import com.moxtar_1s.android.disease_charts.utils.SortUtil;

import org.json.JSONArray;
Expand Down Expand Up @@ -96,11 +97,11 @@ private void loadGlobalIntroBean() {

private String format(int cases, int increase) {
if (increase > 0) {
return cases + "\n+" + increase;
} else if (increase == 0) {
return cases + "\n--";
return NumberUtil.formatNumber(cases) + "\n+" + NumberUtil.formatNumber(increase);
} else if (increase < 0) {
return NumberUtil.formatNumber(cases) + "\n" + NumberUtil.formatNumber(increase);
} else {
return cases + "\n" + increase;
return NumberUtil.formatNumber(cases) + "\n--";
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.moxtar_1s.android.disease_charts.utils;

import java.text.DecimalFormat;

public class NumberUtil {
public static String formatNumber(int number) {
DecimalFormat df = new DecimalFormat("#,###");
return df.format(number);
}
}

0 comments on commit 473427f

Please sign in to comment.