在基本适配器中显示Pojo的原始价值的一半



我在基本适配器类中获得了价值。我想显示其中一半并将其设置为TextView。如何在Adapter类中执行此操作?

holder.txtDiscount.setText(pojo.getCashback().substring(2)+"%"+"nDiscount");

pojo.getCashback()获取值。我想显示其中的一半。例如,如果我获得0.20,则TextView应显示0.10。

您唯一要做的就是将您的价值除以2。

double half = Integer.parseInt(pojo.getCashback().substring(2)) / 2.0;

然后在您的TextView中显示:

holder.txtDiscount.setText(half + "%" + "nDiscount");

您可以通过:

分开
double totalValue = Double.parseDouble(YourString);
double result = ((double) totalValue ) / 2;

最新更新