![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| mail function problem | jwholey | Shell Programming and Scripting | 4 | 05-01-2008 12:21 PM |
| problem, with if condition in function | gurukottur | Shell Programming and Scripting | 4 | 04-24-2008 03:57 PM |
| PERL function problem | avadhani | Shell Programming and Scripting | 2 | 06-15-2005 05:18 AM |
| Problem with the strlen function in ksh | steiner | Shell Programming and Scripting | 3 | 07-24-2003 09:39 AM |
| rexec() function problem | lcmoreno | High Level Programming | 7 | 01-08-2002 10:19 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
problem in awk int() function
awk -vwgt=$vWeight -vfac=$vFactor '
BEGIN { printf("wgt:" wgt "\n"); printf("factor:" fac "\n"); total = sprintf("%.0f", wgt * fac); total2 = sprintf("%.0f", int(wgt * fac)); printf("total:" total "\n"); printf("total2:" total2 "\n"); } ' if vWeight=326.4 vFactor=100 the result would be: total:32640 total2:32639 Could anyone know how is 32639 calucated? thanks! |
|
||||
|
Rounding
Rounding!
Try this... awk 'BEGIN {printf("%.50f\n", 326.4*100)}' and you should see something like... 32639.99999999999636202119290828704833984375000000000000 Including the int function simply rounds the output down to 32639. 'int' does not round to the nearest integer printf (or sprintf) rounds by default when using %f, so without the int, it will display 32640. HTH. Jerry |
|
||||
|
Rounding numbers in awk
I send you an attached file with the awk source of a simple function for rounding numbers in any scale. Of course there are some limits, but you can edit the code and make it better (if you can).
Have fun. Last edited by Panos1962; 01-02-2009 at 10:04 AM.. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|