我在 bash 中编写了一个简单的帐户脚本,但我找不到显示浮点值的标准方法。这是使用 awk 的最佳解决方案吗?余额也打印出 0.00,我忘了包括什么吗?
#!/bin/bash
function printBalance()
{
echo | awk 'BEGIN { printf "\nCurrent balance: %.2f\n", balance }'
sleep 1
}
function makeWithdraw()
{
echo -en "\nWithdraw an amount: "
read deposit
if [ "$withdraw" -gt "$balance" ]; then
echo -en "\nInsufficient funds"
sleep 1
else
balance=$(( balance - withdraw ))
fi
}
balance=$((RANDOM%100+1))
# code continues...