Reputation: 65
var1=126
var2=16
var1/var2 = 7.87
My requirement is if the output value comes in decimal, then add 1 to the integer i.e in this case 7+1 =8
. How can I do that?
Upvotes: 0
Views: 70
Reputation: 241848
You can use the modulo operator %
:
#! /bin/bash
var1=126
var2=16
(( result = var1 / var2 ))
(( var1 % var2 && ++ result )) # If there's a remainder, add 1 to result.
echo $result
Upvotes: 1