![]() |
| ||
| integer division! oh the fun :-) Hi guys, Will keep this short and sweet. Trying to do integer devision to *decimial places but i dont think the version of ksh installed on solaris 10 supports this as they would need to be declared as floats. Is this correct? If there isnt a way of doing it with ksh is there another way to do it integer rBytes=`kstat -p -c net -n $Interface -s rbytes64 1 2 |\ Gives the output: rBytes=694127 oBytes=769020 Whereas it should give: rBytes=694127 oBytes=769020 |
| ||
| Re: integer division! oh the fun :-) Personally, I would just do awk '{print $2 / 1000000 }'and stop worrying about just how good the maths is in the shell. Also, awk has printf() as well, so you've got really good control over the format as well. |
| ||
| Re: integer division! oh the fun :-) ok not to familar with awk had a little play but getting errors. So if i wanted to manipluate the varialbes and then put them into the new varialbles read and write how would i do it. Also would be good if you could show me how to do it to two decimal places. Interface=`cat $Interfaces | sed -n $k"p"` |
| ||
| Re: integer division! oh the fun :-) > awk '{print $rBytes / 100000}'END How is that anything like what I posted? |
| ||
| Re: integer division! oh the fun :-) haha i was trying to put the value into a varailble and was getting frusturtated and trying different things! thanks for your help! |
| ||
| Re: integer division! oh the fun :-) Hey there, One way to pass variables to awk (so you don't have to use double quotes) is with the -v flag, like Quote:
Best wishes, Mike |
| ||
| Re: integer division! oh the fun :-) bc(1) is your friend. It computes to arbitrary precision. "-e" tells bash to interpret \x sequences; ksh might not need it. . |
| All times are GMT -4. The time now is 6:37 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC