我正在构建一个应用程序来计算两次之间的时间 我添加了两个格式化字段来获取开始时间和停止时间。
如何使用格式化字段计算两小时内的时间?我尝试将字符串解析为 float ,但它不起作用
float Start, End ,result = 0;
//Parse the string to a float
Start = Float.parseFloat(Start_Input.getText());
End = Float.parseFloat(Stop_Input.getText());
result = End-Start;
OutPut_Area.setText(String.valueOf(result));
最佳答案
为什么使用float来接受时间?我认为当时间是时间戳时,使用long来接受时间更合理。
如果你使用float来接受时间,你应该用它来计算:
BigDecimal.subtract(new BigDecimal(float doubleValue)).doubleValue()
而不是:
-
关于java - 使用格式化字段进行数学运算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59062948/