[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: scientific notation in Bash
From: |
Greg Wooledge |
Subject: |
Re: scientific notation in Bash |
Date: |
Tue, 15 Mar 2022 08:13:28 -0400 |
On Tue, Mar 15, 2022 at 01:03:54PM +0100, Ante Bilandzic wrote:
> However, there seems to be the corner case, when I was expecting that Bash
> will be able to handle the problem internally: the case when an integer is
> written in a scientific notation, using 'e' or 'E'.
As you have already observed, bash doesn't handle that. You would need
to run some external utility (e.g. awk) to convert those into a form
that bash can read.
unicorn:~$ awk -v n=4.4e5 'BEGIN {printf("%d\n", n)}'
440000
unicorn:~$ awk -v n=4.4e9 'BEGIN {printf("%d\n", n)}'
4400000000