这个问题在这里已有答案:
如何在bash中使用浮点除法? 11个答案我知道bash不支持长时间划分,这个问题可能会被归结为地狱,但在这里它会发生。 我查找了一个bash work-around给了我一个假设的数值。 例如,这就是我得到的:
#!/bin/bash SMALL_NUMBER=4 LARGE_NUMBER=56100 MATH_PROBLEM=$((100*$SMALL_NUMBER/$LARGE_NUMBER)) echo $MATH_PROBLEM我执行代码,输出总是0.我认为将表达式乘以100将解决这个问题,但显然不是。 有人能告诉我这是怎么回事吗?
This question already has an answer here:
How do I use floating-point division in bash? 14 answersI know bash doesn't support long division and this question is probably going to be downvoted to hell, but here it goes. I looked up a bash work-around to giving me a supposed numeric value for the division. For example, this is what I got:
#!/bin/bash SMALL_NUMBER=4 LARGE_NUMBER=56100 MATH_PROBLEM=$((100*$SMALL_NUMBER/$LARGE_NUMBER)) echo $MATH_PROBLEMI execute the code and the output is always 0. I thought multiplying the expression by 100 would fix this but apparently not. Can someone tell me what is going on with this?
最满意答案
Bash只做整数,而不是浮点数; 您必须将任务委派给诸如bc的工具
Bash only does integers, not floats; you must delegate the task to a tool such as bc
更多推荐
发布评论