in my ksh script I need to calculate only integer numbers
Sometimes I get float numbers such as 3.49 or 4.8…etc
so I need to translate the float numbers to integer’s numbers according to the following rules (examples)
3.49 will be 3
2.9 will be 3
4.1 will be 4
23.51 will be 24
982.4999 will be 982
10.5 will be 11 ( this example if float is .5 then it will roundup )
Please advice how to do this in ksh or awk or perl
Or
any other language that can be run in my ksh script
After a brief google session, I found that
printfseems to be able to do the job, at least in bash (couldn’t find an online interpreter that does ksh).Code at: http://ideone.com/nEFYF
Note: perl might be overkill, like Marius says, but here’s a perl way:
The perl module Math::Round seems to handle the job.
One-liner:
Script:
Script output: