6. shell&python中科学计数字符串转数字

1. shell中科学计数字符串转数字

str1='1.50251e+07'

str2=$(echo $str1| awk '{printf("%d\n",$0+0.5)}')

2. python中科学计数字符串转数字

str1='1.50251e+07'

num='{:.5f}'.format(float(str1))  #只能用float先强制类型转换,如果用int()会抛出报错:

ValueError: invalid literal for int() with base 10: '1.50251e+07'

你可能感兴趣的:(6. shell&python中科学计数字符串转数字)