如何在shell中将科学表示法中的值转换为十进制?(首选C壳)
另外,我希望将它从e-12转换为e-9,然后再转换为shell。
42.53e-12至0.04253。我必须这样做是为了一份名单。
发布于 2018-02-11 21:27:20
printf将从shell为您做这件事。
$ FOO=42.53e-12
$ BAR=$(printf "%.14f" $FOO)
$ echo $BAR
0.00000000004253
$在ancient+arcane C-shell中,这将是.
$ set FOO=42.53e-12
$ set BAR=`printf "%.14f" $FOO`
$ echo $BAR
0.00000000004253
$发布于 2020-04-03 17:19:02
您可以尝试以下几种方法:
echo "3.0000000000e+02" | awk '{printf("%d",$0);}'或者如果你希望有小数
echo ""3.676361000e+02" | awk '{printf("%0.2f",$0);}'发布于 2018-10-20 16:41:10
可能不是最好的解决方案,但我设法做到了一个小黑客。你可以这样做-
scientific='42.53e-12'
base=$(echo $scientific | cut -d 'e' -f1)
exp=$(($(echo $scientific | cut -d 'e' -f2)*1))
converted=$(bc -l <<< "$base*(10^$exp)")
>> .00000000004253000000https://unix.stackexchange.com/questions/423453
复制相似问题