如何将数字更改为科学编号并获得最小值(科学编号格式) [英] How change a number to Scientific Number and get the minimum value (Scientific Number format)

查看:109
本文介绍了如何将数字更改为科学编号并获得最小值(科学编号格式)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Linux中将数字转换为科学数字?

How change a number to scientific number in linux?

号码

0.000111309

科学编号

1.11E-04

使用awk,python或perl.谢谢.

Used awk,python or perl. Thanks.

而且,如何从python中的许多科学数中获取最小值?就像bash中的sort -g | sed -n '$p'.

And, how to get the minimum value from many Scientific Number in python? Just like sort -g | sed -n '$p' in bash.

打印时python是否可以将数字自动更改为科学编号? 我发现打印时0会变成0.000000e + 00.

whether python can change automatically number to Scientific Number when print? I'm find the 0 will become to 0.000000e+00 when print.

推荐答案

如果您需要科学计数法,则需要使用%e%E格式说明符

If you need scientific notation you need to use the %e or %E format specifier

使用

awk 'BEGIN{printf("%.2E\n",0.000111309)}'
1.11E-04

使用

akshay@db-3325:~$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import decimal
>>> '%.2E' % decimal.Decimal('0.000111309')
'1.11E-04'
>>> 

使用

akshay@db-3325:~$ perl -e 'printf("%.2E\n",0.000111309)'
1.11E-04

使用

akshay@db-3325:~$ printf "%.2E\n" 0.000111309
1.11E-04

这篇关于如何将数字更改为科学编号并获得最小值(科学编号格式)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆