gpt4 book ai didi

java - 如何将特定格式的字符串转换为 double

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:33:09 24 4
gpt4 key购买 nike

我正在使用 getText() 从 xpath 中获取字符串。字符串是 "500.00/="现在我想将它转换成 double 以便我可以添加它,但问题是当我使用 getText() 我是也得到“/=”,那么如何排除这种额外的字符串格式

//以字符串形式获取金额

String actualbookfees_amount = driver.findElement(By.xpath("//[@id='charges']/table[2]/tbody/tr[1]/td[2]")).getText();

String WHT_amount= driver.findElement(By.xpath("//[@id='charges']/table[2]/tbody/tr[2]/td[2]")).getText();

String numPlate_amount = driver.findElement(By.xpath("//[@id='charges']/table[2]/tbody/tr[3]/td[2]")).getText();

String registrationfees_amount= driver.findElement(By.xpath("//[@id='charges']/table[2]/tbody/tr[4]/td[2]")).getText();

String Motor_vehicle=driver.findElement(By.xpath("//*[@id='charges']/table[2]/tbody/tr[5]/td[2]")).getText();

String With_amount=driver.findElement(By.xpath("//*[@id='charges']/table[2]/tbody/tr[5]/td[2]")).getText();

//converting amount in integers
double actualbookfees_amount_int = Double.valueOf(actualbookfees_amount);
double WHT_amount_int = Double.valueOf(WHT_amount);
double numPlate_amount_int = Double.valueOf(numPlate_amount);
double registrationfees_amount_int = Double.valueOf(registrationfees_amount);
double Motor_vehicle_int = Double.valueOf(Motor_vehicle);
double With_amount_int = Double.valueOf(With_amount);

double total_amount_int= actualbookfees_amount_int + WHT_amount_int+numPlate_amount_int+ registrationfees_amount_int+Motor_vehicle_int+With_amount_int;
System.out.println(total_amount_int);

最佳答案

您可以通过将“,”替换为“”来实现。

String actualbookfees_amount = "100,000.00 /=";

actualbookfees_amount = actualbookfees_amount.replace(",", "");
double actualbookfees_amount_int = Double.valueOf(actualbookfees_amount.substring(0, actualbookfees_amount.length()-2));
System.out.println(actualbookfees_amount_int);

关于java - 如何将特定格式的字符串转换为 double ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49645752/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com