【问题标题】:Minus function not working in my activity减号功能在我的活动中不起作用
【发布时间】:2019-03-12 13:24:06
【问题描述】:

我想从当前读数中减少“以前的仪表读数”。但仍会针对当前读数进行账单计算。看起来很简单,但我找不到问题所在。

Intent i = getIntent();
    final double con = i.getDoubleExtra("Value", 0.0);

    final double pre = i.getDoubleExtra("Value1", 0.0);

    cur_units.setText("" + con);
    pre_units.setText("" + pre);

       Test = con - pre;

    Units = Test;
    if (Units <= 5) {
        Amount = Units * 12;
        Ser_Charge = 50;
    } else if (Units <= 10) {
        // For the First Five Units Charge = 60 (5 * 12)
        // Next, we are removing those 5 units from total units
        Amount = 60 + ((Units - 5) * 16);
        Ser_Charge = 65;
    } else if (Units <= 15) {
        // First Five Units charge = 60, and 6 - 10 is 80 (5 * 16)
        // Next, we are removing those 10 units from total units
        Amount = 60 + 80 + ((Units - 10) * 20);
        Ser_Charge = 70;
    } else if (Units <= 20) {

【问题讨论】:

  • 您没有得到准确的输出吗?你有什么问题?请解释一下。
  • 我想得到单位从当前单位减少以前的米单位。但只计算当前单位。
  • 显示您的完整代码。告诉我 Units and Test 的数据类型是什么。
  • 我无法添加完整的代码。 Bcoz 太大了。
  • 抱歉,您没有很好地解释问题。

标签: android calculation


【解决方案1】:

检查您的单元/测试是否是双倍的;如果它们是 int,con-pre 结果将被强制转换: 5.0 - 0.2 = 5

【讨论】:

  • 我想你检查了 pre 设置是否正确(不是默认值:0.0)?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-02-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-10
  • 2015-07-26
相关资源
最近更新 更多