On 10/2/07, Kurt H Maier <karmaflux_AT_gmail.com> wrote:
> If anyone knows how to cast
> floats to int in bash let me know. :V
>
Not exactly efficient, but it works (pay attention to the spaces is
round(), `expr` is especially picky...)::
$ floor () { echo "$1" | sed -e 's|\.[0-9]\+||'; }
$ floor 0.1
0
$ floor 10.89
10
$ ceil () { expr $(floor "$1") + 1; }
$ ceil 0.1
1
$ ceil 10.89
11
$ round () { expr $(echo "$1" | sed -e
's|\.[0-4][0-9]*||;s|\.[5-9][0-9]*| + 1|;'); }
$ round 10.89
11
$ round 0.1
0
Riccardo
Received on Tue Oct 02 2007 - 17:10:22 UTC
This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 14:56:55 UTC