bug-bash
[Top][All Lists]
Advanced

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

Re: REQUEST - bash floating point math support


From: Greg Wooledge
Subject: Re: REQUEST - bash floating point math support
Date: Wed, 5 Jun 2024 14:11:32 -0400

On Wed, Jun 05, 2024 at 01:31:20PM -0400, Saint Michael wrote:
> the most obvious use of floating variables would be to compare
> balances and to branch based on if a balance is lower than a certain
> value
> I use:
> t=$(python3 -c "import math;print($balance > 0)")
> and the
> if [ "$t" == "False" ];then
> echo "Result <= 0 [$t] Client $clname $clid Balance $balance"
> fi
> There must be a solution without Awk or Python or BC. Internal to bash

The example you show is just comparing to 0, which is trivial.  If
the $balance variable begins with "-" then it's negative.  If it's "0"
then it's zero.  Otherwise it's positive.

For comparing two arbitrary variables which contain strings representing
floating point numbers, you're correct -- awk or bc would be the minimal
solution.



reply via email to

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