round in KSH

Is there an easy way to round a number up in Korn shell?

ie. 10.4 --> 11

Thanks.

printf "%.0f\n" 10.4

This produces 10, which is the correct result of rounding 10.4

Write yourself a quick C program to round-up using ceil...

# cat /var/tmp/abs.c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

float li;
int x;

main( int argc, char **argv ) {
   li = atof(argv[1]);
   x = ceil( li );
   printf( "%d\n", x );
   return 0;
}
# cc -lm /var/tmp/abs.c -o /var/tmp/abs
# /var/tmp/abs 129.12
130
# /var/tmp/abs 3
3
# /var/tmp/abs 3.6
4

Cheers
ZB

Greatly appreciate the replies.

WOW...it's surprising that there isn't a built-in function to perform rounding UP.

ksh88 only supports integers. ksh93 has floating point and can do rounding internally.

$
$ typeset -F r
$ ((r=2.0/3.0))
$ echo $r
0.6666666667
$ typeset -i ir
$ ((ir=r+.5))
$ echo $ir
1
$

Now why did I know Perderabo had the solution in his bag of tricks !!!

Thanks much Perderabo !!!

Hi Guys,

How to do rounding off in bash

10.3 ---> 10
10.6 ---> 11

Regards,
Gaurav Goel