Rounding off the value of Floating point value

Hello,

i have some variables say:
x=1.4
y=3.7

I wish to round off these values to :
x = 2 (after rounding off)
y = 4 (after rounding off)

I am stuck.
Please help.

$ typeset -i var
$ var=100.100
$ echo $var
100

Hi aju_kup,
Thanks for replying.

typeset -i var
var=100.500
echo $var

When i try your suggestion, it gives me an error which is:
check4.sh: line 2: 100.500: syntax error in expression (error token is ".500")

here check4.sh is the file which contained your suggested code.

I am working on KShell.

Please see to it.
Thanks:)

can u pls show me ur script. even I am using ksh

Sure friend,

rowCountEntered=98
totalRowCount=1000

numberOfFilesGenerated=`echo $totalRowCount $rowCountEntered | awk '{print $1/$2}'`

echo $numberOfFilesGenerated
10.20

Instead of 10.20, i want the variable numberOfFilesGenerated should return 11.

In Anticipation.

Try this:

 numberOfFilesGenerated=`echo $totalRowCount $rowCountEntered | awk '{printf("%d", $1/$2+0.9}'`

Regards

rowCountEntered=98
totalRowCount=1000

typeset -i numberOfFilesGenerated
numberOfFilesGenerated=`echo $totalRowCount $rowCountEntered | awk '{print $1/$2}'`

echo $numberOfFilesGenerated
10

Thanks Franklin,

it worked!!!

aju_kup,
I was seeking the upper integer i.e. the floor of any floating point value.

Thanks to both of you for your valuable help.!!!!
:slight_smile: