round number in bash

Mar 09, 2011 11:21

http://tech.therealdavidfield.com/post/3581061279/question-how-can-i-round-a-number-in-bash

echo "($float+0.5)/1" | bc

If your floating point number is in a variable called float then this will round up or down accordingly. As in 1.0 and 1.4 round to 1, while 1.5 and 1.9 round to 2.

bash scripting

Previous post Next post
Up