This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Fwd: Re: Rounding off real (floating point) values - bash to awk
- From: Eliot Moss <moss at cs dot umass dot edu>
- To: cygwin <cygwin at cygwin dot com>
- Date: Thu, 26 Nov 2015 13:00:34 -0500
- Subject: Fwd: Re: Rounding off real (floating point) values - bash to awk
- Authentication-results: sourceware.org; auth=none
- References: <56574877 dot 5080100 at cs dot umass dot edu>
- Reply-to: moss at cs dot umass dot edu
On 11/26/2015 12:20 PM, Helmut Karlowski wrote:
---------------------------------------------------
On Thu, Nov 26, 2015 at 10:29 AM, Steven Penny wrote:
echo 3.7 | awk '{printf "%.0f", $0}'
Another option
awk 'BEGIN {printf "%.0f", ARGV[1]}' 3.7
#4:
printf "%3.0f\n" 3.7
Yes, while bash does not itself "do" floating point arithmetic,
it does have a printf builtin. Also, you can do computations
using dc, and arbitrary precision calculator program, and you
can control the number of digits of precision used for output,
etc.
Regards -- Eliot Moss
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple