简体   繁体   English

如何将两个数组字符串的值求和并存储到Java Selenium中的另一个数组列表中?

[英]How to do sum of two array string's value and store into another array list in java selenium?

I have 4 Array that store at least 6 value. 我有4个存储至少6个值的数组。

ArrayList<String> GrossAmt = new ArrayList<String>();
ArrayList<String> TaxAmt = new ArrayList<String>();
ArrayList<String> DiscAmt = new ArrayList<String>();
ArrayList<String> FinalAmt = new ArrayList<String>();

GrossAmt = [ 66.5928,  110.9880,  369.9592,  92.4898,  249.7221,  27.7469] 
TaxAmt = [ 3.8632,  6.4386,  21.4621,  5.3655,  14.4869,  1.6097] 
DiscAmt =[ 2.2137,  3.6895,  12.2984,  3.0746,  8.3014,  0.9224] 
FinalAmt =[ 68.2423,  113.7371,  379.1229,  94.7807,  255.9076,  28.4342]

I need to get the result of grossAmt+TaxAmt-DiscAmt and compare with FinalAmt. 我需要获取GrossAmt + TaxAmt-DiscAmt的结果,并与FinalAmt进行比较。

for(int g = 0; g < GrossAmt.size(); g++){
                int Expected = 0;
                Expected = Integer.valueOf(GrossAmt.get(g)) + Integer.valueOf(TaxAmt.get(g))- Integer.valueOf(DiscAmt.get(g));
                int Actual = Integer.valueOf(FinalAmt.get(g));
                LogFileControl.logInfo(Actual);
                LogFileControl.logInfo(Expected);


             if (Actual == Expected ){

                 LogFileControl.logInfo("Final Amount Passed!");

             }else
             {
                 LogFileControl.logError(("Actual: " + Actual) + " Expected: " + Expected);

             }

But i got error for this. 但是我对此有错误。

Looks like the amounts are in decimal whereas you are performing the comparison by converting them into integer . 看起来金额是decimal而您正在通过将它们转换为integer来执行比较。 I would recommend using double literal type for this comparison, eg: 我建议使用double文字类型进行此比较,例如:

ArrayList<String> GrossAmt = new ArrayList<String>();
ArrayList<String> TaxAmt = new ArrayList<String>();
ArrayList<String> DiscAmt = new ArrayList<String>();
ArrayList<String> FinalAmt = new ArrayList<String>();

for (int g = 0; g < GrossAmt.size(); g++) {
    double Expected = 0;
    Expected = Double.valueOf(GrossAmt.get(g)) + Double.valueOf(TaxAmt.get(g))
            - Double.valueOf(DiscAmt.get(g));
    double Actual = Double.valueOf(FinalAmt.get(g));
    LogFileControl.logInfo(Actual);
    LogFileControl.logInfo(Expected);

    if (Actual == Expected) {
        LogFileControl.logInfo("Final Amount Passed!");
    } else {
        LogFileControl.logError(("Actual: " + Actual) + " Expected: " + Expected);
    }
}

Try as follows A and B are two different ArrayLists 尝试如下操作A和B是两个不同的ArrayLists

ArrayList AB = new ArrayList();

AB.addAll(A);
AB.addAll(B);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将sum的值存储在新数组b中 - How do i store the value of sum in the new array b 从列表字符串存储到另一个数组列表 - store from list string to another array list 如何从java中的字符串数组中获取两个随机值的和? - how to get the sum of the two random value from an array of strings in java? 如何在 java spring 引导中对 json 数组的两个值求和? - How to sum value of two values of a json array in java spring boot? 如何在硒中打印列表数组的最后一个字符串值? - How to print last string value of List Array in selenium? 如何将字符串值存储到数组字符串,并可以在另一个类中调用该数组以在单行中打印为字符串 - how to store string value to array string and can call that array in another class to Print as string in single line Java - 将对象数组存储为另一个对象的值并调用该值的字段 - Java - Store array of objects as another object's value and call that value's field 如何在java ..中的Char数组中存储字符串值? - How to Store the String Value in Char array in java..? Java中单个字符串数组中两个integer数组的元素之和 - Sum of elements of two integer array in a single string array in Java 您如何创建数组以在Java中存储正则表达式字符串匹配? - How do you create an array to store regex string matches in java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM