我需要以非指数形式在JavaScript中获取极大数字的值.Number.toFixed只是以指数形式将其作为字符串返回,这比我的更糟糕.
这是Number.toFixed回报:
>>> x = 1e+31
1e+31
>>> x.toFixed()
"1e+31"
Run Code Online (Sandbox Code Playgroud)
Number.toPrecision 也不起作用:
>>> x = 1e+31
1e+31
>>> x.toPrecision( 21 )
"9.99999999999999963590e+30"
Run Code Online (Sandbox Code Playgroud)
我想要的是:
>>> x = 1e+31
1e+31
>>> x.toNotExponential()
"10000000000000000000000000000000"
Run Code Online (Sandbox Code Playgroud)
我可以编写自己的解析器,但如果存在,我宁愿使用本机JS方法.
我不想在我的R会话中的任何计算结果中看到任何科学记数法.我希望看到所有实际数字,最好在每三个数字后面加一个逗号(,).
我怎样才能做到这一点? options(scipen = 999)不削减它.
我有一个简单的情节:
#!/usr/bin/Rscript
png('plot.png')
y <- c(102, 258, 2314)
x <- c(482563, 922167, 4462665)
plot(x,y)
dev.off()
Run Code Online (Sandbox Code Playgroud)
R对y轴使用500,1000,1500等.有没有办法可以使用科学记数法表示y轴并放在轴* 10^3的顶部,如下图所示?

是否存在提供工程符号格式(如String)的现有Haskell函数?
如果没有,我读到printf可以通过添加实例来扩展PrintfArg.你相信这是一个很好的解决方案吗?
通过工程符号,我的意思是指数符号,其指数是3的倍数.
floating-point formatting haskell scientific-notation floating-point-precision
我有一个条形图,它看起来像我想要的样子,除了 y 轴上的科学记数法之外。
其他一些解决方案包括使用
ax.yaxis.set_major_formatter(tick)
Run Code Online (Sandbox Code Playgroud)
这不起作用。另外,我尝试检查这是否是一个偏移问题,但它应该显示一个“+”号,但在本例中没有。
每当我使用:
plt.ticklabel_format(style='plain')
Run Code Online (Sandbox Code Playgroud)
我收到一条错误消息:
Traceback (most recent call last):
File "C:\Python\lib\site-packages\matplotlib\axes\_base.py", line 2831, in ticklabel_format
self.xaxis.major.formatter.set_scientific(sb)
AttributeError: 'FixedFormatter' object has no attribute 'set_scientific'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Python/Projects/Kaggle 1.py", line 13, in <module>
plt.ticklabel_format(style='plain')
File "C:\Python\lib\site-packages\matplotlib\pyplot.py", line 2982, in ticklabel_format
useMathText=useMathText)
File "C:\Python\lib\site-packages\matplotlib\axes\_base.py", line 2856, in ticklabel_format
"This method only works with the ScalarFormatter.")
AttributeError: This method only works with the ScalarFormatter.
Run Code Online (Sandbox Code Playgroud)
我研究过这个 ScalarFormatter,但我无法更清楚地了解它为什么不起作用。我尝试将其显式包含在代码中,但它不起作用。 …
我放入.describe()一个数据框,输出看起来不太好。我希望输出显示整数,而不是用指数简化。
输入:
df["A"].describe()
Run Code Online (Sandbox Code Playgroud)
输出的样子:
count 6.000000e+01
mean 7.123568e+04
std 2.144483e+05
min 1.000000e+02
25% 2.770080e+03
50% 1.557920e+04
75% 4.348470e+04
max 1.592640e+06
Name: A, dtype: float64
Run Code Online (Sandbox Code Playgroud)
预期输出:
count 60.0
mean 7123.568
std 214448.3
min 100.0000
25% 2770.080
50% 15579.20
75% 43484.70
max 1592640.0
Name: A, dtype: float64
Run Code Online (Sandbox Code Playgroud) 当以科学格式显示数字时,我还没有找到一种方法只获取 3 的倍数的指数。我也没有成功编写一个简单的自定义格式化函数。
这是一个简单的例子:
使用 python 的科学记数法的正常行为.format():
numbers = [1.2e-2, 1.3e-3, 1.5e5, 1.6e6]
for n in numbers:
print("{:.E}".format(n))
Run Code Online (Sandbox Code Playgroud)
>>> 1.20E-02
1.30E-03
1.50E+05
1.60E+06
Run Code Online (Sandbox Code Playgroud)
但是,我需要以下输出:
>>> 12.00E-03
1.30E-03
15.00E+06
1.60E+06
Run Code Online (Sandbox Code Playgroud)
有谁知道我获得所需格式的便捷方法?
如何将科学记数法转换为浮点数?这是我想要避免的一个例子:
Python 2.7.3 (default, Apr 14 2012, 08:58:41) [GCC] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a=[78.40816326530613, 245068094.16326532]
>>> print a[0]/a[1]
3.19944395589e-07
>>> print float(a[0]/a[1])
3.19944395589e-07
>>> print float(a[0])/float(a[1])
3.19944395589e-07
Run Code Online (Sandbox Code Playgroud) 在最长的时间里,我想IsNumeric("1.23E45")回归True是因为"E"代表科学记数法,使1.23E45为1.23x10 45.
最近我注意到IsNumeric("1.23D34") 也回来了True,我为什么难过.
双方D并E产生相同的结果:
?val("1.23d45")
1.23E+45
?val("1.23e45")
1.23E+45
Run Code Online (Sandbox Code Playgroud)
怎么会?
我试图减少一些计算后得到的小数位数.print()我的问题出现在哪里看起来像这样:
print("Mean resistivity: {res} Ohm m".format(res=np.mean(resistivity)))
Run Code Online (Sandbox Code Playgroud)
它输出这个:
Mean resistivity: 1.6628449915450776e-08 Ohm m
Run Code Online (Sandbox Code Playgroud)
现在我想减少打印到3的小数位数.我尝试用字符串格式化,如下所示:
print("Mean resistivity: {res:.3f} Ohm m".format(res=np.mean(resistivity)))
Run Code Online (Sandbox Code Playgroud)
但是,此代码打印:
Mean resistivity: 0.000 Ohm m
Run Code Online (Sandbox Code Playgroud)
我真正想要的是这个:
Mean resistivity: 1.663e-8 Ohm m
Run Code Online (Sandbox Code Playgroud)
如何将格式化res为仅显示为科学记数法,但只有3位小数?