Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ### 在bash中进行小数比较
- #### 1 `bc`
- ```bash
- if [ `echo "3.4 < 4.5" | bc` -eq 1 ];then
- echo yes
- else
- echo no
- fi
- ```
- or
- ```
- if [ bc <<< `echo "3.4 < 4.5" ` -eq 1 ];then
- echo yes
- else
- echo no
- fi
- ```
- #### 2 {} 分别比较整数和小数部分
- ```bash
- a=1.9
- b=2.3
- if (( ${a%%.*} < ${b%%.*} || ${a%%.*} == ${b%%.*} && ${a##*.} < ${b##*.} )) ;then
- echo yes
- else
- echo no
- fi
- ```
Add Comment
Please, Sign In to add comment