verify / compare prices (sale vs. strikethrough price)

hi there,

i need your help. i want to compare / verify, that the displayed sale price (in a online shop) is lower than the regular price.

for example:

  • strikethrough price: $69.00
  • sale price: $50.99

i’ve got the values as a string, but i need these variables as a number to use “verify greater/lower than”. Otherwise i can accept to write these values to an external excel file.

Thank you!
Best
Fabian

hi,
one way to do it

import java.util.regex.Matcher;
import java.util.regex.Pattern;
    String one = "strikethrough price: $69.00";
    String two ="sale price: $50.99";

    String pattern = "([\\d.\\d]+)";
    List<String> prices = new ArrayList<>();
    List<String> prices2 = new ArrayList<>();
    prices.add(one);
    prices.add(two);
    // Create a Pattern object
    Pattern r = Pattern.compile(pattern);
    // Now create matcher object.
    for (String line : prices) {
        Matcher m = r.matcher(line);
        if (m.find()) {
            //System.out.println("Found value: " + m.group(0));
            prices2.add(m.group(0));
        }
    }
    System.out.println(prices2);

    double priceOne = Double.parseDouble(prices2.get(0));
    double priceTwo = Double.parseDouble(prices2.get(1));

    if (priceOne > priceTwo){
        System.out.println("Price one is higher than price two");
    }
    else if(priceOne == priceTwo){
        System.out.println("Prices are equals");
    }
    else{
        System.out.println("Price two is higher than price one");
    }