无法在外壳脚本中获得浮动值作为输出
当我尝试像您可以在下面的代码段中看到的值分配值时,当值进入浮点时,它并没有向我显示浮点吗?它只是打印0。我正在对MB进行GB转换。 大约2-3个值的转换
任何人都可以帮助我让我看到 0之后的
echo -e "Enter your value in MB! \c"
read -r userINPUT
。 >转换结果:
echo "In GB it is: $((userINPUT / 1024))"
输出我得到:
Enter your Frist Number! 25
In GB it is: 0
When I try to divide values like you can see in below code snippet when value gets in float it doesn't shows me the float? It just prints 0. I'm doing MB to GB conversion. Anybody can help me to let me see the conversion to some 2-3 values after 0. like 0.2545
Taking an input from user:
echo -e "Enter your value in MB! \c"
read -r userINPUT
Converted result:
echo "In GB it is: $((userINPUT / 1024))"
Output I'm getting:
Enter your Frist Number! 25
In GB it is: 0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
bash不支持浮点算术。
您可以使用BC命令对浮点值进行操作。
喜欢:
或者更好,您可以安装和使用命令 numfmt 转换
https://man7.org/linux/man-pages/man1/numfmt.1.html
Bash does not support floating point arithmetic.
You can use bc command to do the operations on float values.
Like:
Or better you can install and use the command numfmt for the conversion
https://man7.org/linux/man-pages/man1/numfmt.1.html