Unix shell script, How to do rounding of number ?

Below is my code. I want to check total number of lines and divided it by 2.

Suppose total no of lines =24 then I will divide by 2 = 12 .

But  when total no of lines =23 and then I will divide by 2 it gives 11 . I want 12 because actulay value is 11.5


ncnt=$((`wc -l < AMS_Total_Business_ID.txt` / 2))

Please help.
digs developerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
ncnt=$(( ( `wc -l < AMS_Total_Business_ID.txt` + 1 ) / 2))
0
digs developerAuthor Commented:
But when I divide by 1000 is is not shown correct nmber like by 2.


ncnt=$(( ( `wc -l < AMS_Total_Business_ID.txt` + 1 ) / 1000))

division by value should be change on run time. It may be 500 ,900 or 1000

Please help.
0
ozoCommented:
ncnt=$(( ( `wc -l < AMS_Total_Business_ID.txt` + 500 ) / 1000))
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

digs developerAuthor Commented:
Thank you !
0
digs developerAuthor Commented:
I have one text file ABC_T_B_ID.txt which contains values in one column.
The values may be contain 1 or 1000 or 45000 and so on.

So my requirement is count the total line in a file and divided it by 1000 whatever the value comes that value should be ceil.

suppose
1. no of lines = 1000
   1000/1000 = 1
   
2. no of lines = 2000
   2000/1000 = 2

3. no of lines = 10
   10/1000 = 0.01   I need as 1  
   
4. no of lines = 411
   411/1000 = 0.411   I need as 1  

4. no of lines = 9898
   9898/1000 = 9.898   I need as 10    
   
4. no of lines = 9001
   9001/1000 = 9.001   I need as 10    
   
Below is my code.
Please help.  



ncnt=$(( ( `wc -l < ABC_T_B_ID.txt` + 500 ) / 1000))
0
digs developerAuthor Commented:
Please help
0
digs developerAuthor Commented:
Hello Experts,

Please need help
0
woolmilkporcCommented:
Seems you always want to round up:

ncnt=$(( ( `wc -l < ABC_T_B_ID.txt` + 999 ) / 1000))

More generally:

DIV=1000
ncnt=$(( ( `wc -l < ABC_T_B_ID.txt` + ($DIV-1) ) / $DIV))

Note Always rounding up will (for example) give 46 for 45001 lines divided by 1000. Is this desired?
0
ozoCommented:
ncnt=$(( ( `wc -l < ABC_T_B_ID.txt` + 999 ) / 1000))
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.