标签: scientific-notation

h:inputText 更改为科学记数法

我有一个 h:inputText 控件,我可以在其中输入最多 7 位的数字,它会将它们转换为十进制表示(即输入“9999999”,它将呈现“9999999.0”)。但是,当我输入任何 7 位或更多数字时,它会将其转换为科学记数法(即输入“10000000”并将其呈现为“1.0E7”)。

作为业务需求,我必须以十进制表示法而不是科学记数法来显示它。有没有人有办法做到这一点?

<h:inputText id="tableQuantityId" 
        value="#{fee.tableQuantity}" 
        disabled="#{!fee.selected}" 
        rendered="#{editable}" 
        validator="#{facesValidator.validateQuantity}">
    <a4j:support event="onchange" reRender="messages, feePart" ajaxSingle="true"/>
</h:inputText>
Run Code Online (Sandbox Code Playgroud)

编辑:经过一些进一步的调查,它似乎是从“double”类型中获取当前格式的。(换句话说,您可以将“10000000”分配给双精度数并打印它,它会以科学计数法显示给您)。

所以我进入了我的 getTableQuantity() 方法并将其更改为:

(双版)

public double getTableQuantity() {
    return tableQuantity;
}
Run Code Online (Sandbox Code Playgroud)

(到字符串表示):

public String getTableQuantityFormatted() {

    double d = tableQuantity;
    NumberFormat formatter = new DecimalFormat("###.#####");

    String f = formatter.format(d);
    return f;
}
Run Code Online (Sandbox Code Playgroud)

我在我的 xhtml 中将 "value="#{fee.tableQuantity}" 更改为 value="#{fee.tableQuantityFormatted}"

但是现在我在 xhtml 页面上收到以下错误:

数量值 10000000 不正确。/page/feeContent.xhtml @70,58 value="#{fee.tableQuantityFormatted}":属性 'tableQuantityFormatted' 在 java.lang.String 类型上不可写

formatting jsf textbox scientific-notation

3
推荐指数
1
解决办法
4129
查看次数

e和E在科学记数法中的区别

在 PHP 中,打印为 -9.838335106976932e18 的值与打印为 -9.838335106976932E+18 的值之间有什么区别?(注意“e18”与“E+18”)

php scientific-notation

3
推荐指数
1
解决办法
6032
查看次数

python科学记数法强制前导零

我想让Python2.7以科学记数法打印出浮点数,强制从0开始。例如,假设

a=1234567890e12
print '{:22.16E}'.format(a)
1.2345678900000000E+21
Run Code Online (Sandbox Code Playgroud)

但是,我想要一个如下所示的打印输出:

0.1234567890000000E+22
Run Code Online (Sandbox Code Playgroud)

请注意,由于所需的输出被迫为前导零,因此指数增加了 1。我怎样才能实现这个目标?谢谢。

scientific-notation formatted-input python-2.7

3
推荐指数
1
解决办法
4412
查看次数

将double转换为科学计数法,并在小数点后使用特定数字

我想将double转换为科学记数法,如下所示:

-0.00752382528 => -.752383E-1
Run Code Online (Sandbox Code Playgroud)

我可以用.ToString()或Regex做到这一点吗?

c# double scientific-notation

3
推荐指数
1
解决办法
8022
查看次数

JAVA中将科学记数法的数字转换为十进制数

我有一个问题:如果一个数字的小数点前有 8 位或更多位,则该数字将以科学计数法显示。
有没有一种简单的方法可以通过库或其他方式将此数字转换为十进制?
我开始创建一个手动方法来解析它,但它似乎过于复杂。

任何帮助将不胜感激。

input example: 1.0225556677556E7
Run Code Online (Sandbox Code Playgroud)

编辑:我还需要能够识别以科学计数法表示的数字

java scientific-notation

3
推荐指数
1
解决办法
5575
查看次数

在Python中的符号学图上使用matplotlib防止轴采用科学记数法(10的幂)

我读过这里(如何防止数字在Python matplotlib图中更改为指数形式)和这里(Matplotlib:在对数图中禁用十的幂)并尝试了他们的解决方案但无济于事。

如何将 y 轴转换为显示普通十进制数字而不是科学记数法?请注意,这是 Python 3.5.2。

在此输入图像描述

这是我的代码:

#Imports:
import matplotlib.pyplot as plt

possible_chars = 94
max_length = 8
pw_possibilities = [] 
for num_chars in range(1, max_length+1):
    pw_possibilities.append(possible_chars**num_chars)

x = range(1, max_length+1)
y = pw_possibilities 

#plot 
plt.figure()
plt.semilogy(x, y, 'o-')
plt.xlabel("num chars in password")
plt.ylabel("number of password possibilities")
plt.title("password (PW) possibilities verses # chars in PW")
plt.show()
Run Code Online (Sandbox Code Playgroud)

python plot scientific-notation matplotlib python-3.x

3
推荐指数
1
解决办法
7952
查看次数

将大科学数转换为长数

我现在花了很长时间,尝试在java中转换数字1.2846202978398e+19,但没有任何运气。目前我正在尝试做的事情(long)Double.parseDouble(hashes),但这给出了 9223372036854775807,这显然是不正确的。实际数字应类似于 12855103593745000000。

使用int val = new BigDecimal(stringValue).intValue();return-134589568因为它无法保存结果。将代码切换为long val = new BigDecimal(hashes).longValue();-5600541095311551616 这也是不正确的。

我假设这是由于双精度型与长型相比的大小造成的。

有任何想法吗?

java scientific-notation long-integer

3
推荐指数
1
解决办法
8471
查看次数

使用metafor包将科学记数法中的标签添加到森林图中

所以我正在使用meta.for包进行荟萃分析R.我正准备在科学期刊上发表数据,我想在我的森林地块中添加p值,但科学注释格式为

x10-04
Run Code Online (Sandbox Code Playgroud) 而不是标准

e-04

然而,争论ilabforest功能不接受expression一流的对象,但仅矢量

这是一个例子:

library(metafor)
data(dat.bcg)

## REM 
res <- rma(ai = tpos, bi = tneg, ci = cpos, di = cneg, data = dat.bcg,
           measure = "RR",
           slab = paste(author, year, sep = ", "), method = "REML")
# MADE UP PVALUES
set.seed(513)
p.vals <- runif(nrow(dat.bcg), 1e-6,0.02)

# Format pvalues so only those bellow 0.01 are scientifically notated
p.vals <- ifelse(p.vals < 0.01, 
                 format(p.vals,digits = 3,scientific …
Run Code Online (Sandbox Code Playgroud)

expression r scientific-notation r-forestplot metafor

3
推荐指数
1
解决办法
485
查看次数

禁用 pandas .p​​lot() 函数中的科学记数法和偏移量

我有一个数据框 df ,其中有 2 列,我想将其绘制在一起,并以天数作为索引:

           | col1  | col2   | col3 | ...
2020-01-01 | 1     | 300000 | ...
2020-01-02 | 1000  | 600000 | ...
2020-01-03 | 3000  | 50000  | ...
Run Code Online (Sandbox Code Playgroud)

通过绘制 col1 + col2

df[["col1", "col2"]].plot()
Run Code Online (Sandbox Code Playgroud)

显示从 0 到 1.0 的值,并在顶部“1e6”,如下例所示: https: //i.stack.imgur.com/tJjgX.png

我想要 y 轴上的完整值范围,而不是科学记数法。我如何通过 pandas .p​​lot() 或 matplotlib 来做到这一点?

python plot scientific-notation pandas

3
推荐指数
1
解决办法
7047
查看次数

Python 2.6.6中的小数和科学记数法的问题

我在使用十进制值时遇到困难,在某些情况下需要用于算术,而在其他情况下则需要用作字符串.具体来说,我有一个费率列表,例如:

rates=[0.1,0.000001,0.0000001]
Run Code Online (Sandbox Code Playgroud)

我正在使用它们来指定图像的压缩率.我需要最初将这些值作为数字,因为我需要能够对它们进行排序以确保它们按特定顺序排列.我还希望能够将这些值中的每一个转换为字符串,以便我可以1)将速率嵌入到文件名中,2)将速率和其他详细信息记录在CSV文件中.第一个问题是,当转换为字符串时,任何超过6位小数的浮点数都是科学格式:

>>> str(0.0000001)
'1e-07'
Run Code Online (Sandbox Code Playgroud)

所以我尝试使用Python的Decimal模块,但它也将一些浮点数转换为科学记数法(看起来与我读过的文档相反).例如:

>>> Decimal('1.0000001')
Decimal('1.0000001')
# So far so good, it doesn't convert to scientific notation with 7 decimal places
>>> Decimal('0.0000001')
Decimal('1E-7')
# Scientific notation, back where I started.
Run Code Online (Sandbox Code Playgroud)

我也在调查多个帖子中建议的字符串格式,但我没有运气.任何建议和指针都受到这个Python新手的赞赏.

python string scientific-notation decimal

2
推荐指数
2
解决办法
6466
查看次数