将浮点变量转换为整数? [英] Convert floating point variable to integer?
本文介绍了将浮点变量转换为整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果页面加载时间超过6秒,则下面显示的shell脚本将显示警告。问题是 myduration
变量不是整数。如何将其转换为整数?
The shell script shown below will show a warning if the page takes more than 6 seconds to load. The problem is that the myduration
variable is not an integer. How do I convert it to integer?
myduration=$(curl http://192.168.50.1/mantisbt/view.php?id=1 -w %{time_total}) > /dev/null ; \
[[ $myduration -gt 1 ]] && echo "`date +'%y%m%d%H%M%S'
花了加载页面超过6秒 http://192.168.50.1/mantisbt/view.php?id=1
It took more than 6 seconds to load the page http://192.168.50.1/mantisbt/view.php?id=1
推荐答案
假设$ myduration是小数或整数
Assuming $myduration is a decimal or integer
$ myduration=6.5
$ myduration=$( printf "%.0f" $myduration )
$ echo $myduration
6
这篇关于将浮点变量转换为整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文