Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert floating point variable to integer?

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'

It took more than 6 seconds to load the page http://192.168.50.1/mantisbt/view.php?id=1

like image 641
shantanuo Avatar asked Sep 01 '09 12:09

shantanuo


People also ask

What happens when float convert to integer?

Convert a float to an int always results in a data loss. The trunc() function returns the integer part of a number. The floor() function returns the largest integer less than or equal to a number.

Can you convert float to integer in Python?

Converting Floats to IntegersPython also has a built-in function to convert floats to integers: int() . In this case, 390.8 will be converted to 390 . When converting floats to integers with the int() function, Python cuts off the decimal and remaining numbers of a float to create an integer.

Can float be converted to int in C?

you can convert floating point to integer but the straight conversion has some problem. we cannot get the correct value. if x value 1.9 means.


1 Answers

Assuming $myduration is a decimal or integer

$ myduration=6.5
$ myduration=$( printf "%.0f" $myduration )
$ echo $myduration
6
like image 64
Shizzmo Avatar answered Oct 21 '22 01:10

Shizzmo