我在基本适配器类中获得了价值。我想显示其中一半并将其设置为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;