help-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

re: round to 0 or 5 at the 3 decimal place


From: J Naman
Subject: re: round to 0 or 5 at the 3 decimal place
Date: Fri, 4 Mar 2022 13:13:32 -0500

*Step-by-step:*
x=0.128765
r=100*x; ## r=12.8765
i=int(r) ## i=12.000
i+=.5*(i<int(r+.5)) # # i+=.5 in this case: 12<13.3765
x=i/100; ## x=0.125
printf("%.3d", x ...)

You can write your own awk function roundto05(x);

I used to give this problem as a homework assignment to my students.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]