作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 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/
我是一名优秀的程序员,十分优秀!