Guest User

Untitled

a guest
Jun 20th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. ### 在bash中进行小数比较
  2. #### 1 `bc`
  3. ```bash
  4. if [ `echo "3.4 < 4.5" | bc` -eq 1 ];then
  5. echo yes
  6. else
  7. echo no
  8. fi
  9. ```
  10. or
  11. ```
  12. if [ bc <<< `echo "3.4 < 4.5" ` -eq 1 ];then
  13. echo yes
  14. else
  15. echo no
  16. fi
  17. ```
  18. #### 2 {} 分别比较整数和小数部分
  19. ```bash
  20. a=1.9
  21. b=2.3
  22. if (( ${a%%.*} < ${b%%.*} || ${a%%.*} == ${b%%.*} && ${a##*.} < ${b##*.} )) ;then
  23. echo yes
  24. else
  25. echo no
  26. fi
  27. ```
Add Comment
Please, Sign In to add comment