可以在没有科学记数法的情况下格式化 Double 吗?
我知道关于同一问题的各种帖子。
我的有点不同,可能有点明显,但我需要你的评论。
我目前正在使用 Hibernate Search 和 Lucene 来索引实体属性。
我的实体上有一堆Double 属性。
一旦科学记数法开始,这些使用 Lucene 默认 Bridge 的实体(即负责转换 LongToString 和 StringToLong 的桥)就会给我带来麻烦被使用。
我试图在 .xhtml 上的数据表上显示贷方和借方金额,它们的长度可以长达 18 位数字,以及它们的数据库(DB2 em>) 类型为 BIGINT。
- 我无法更改数据库类型 以龙为例。
- 我无法更改 Double 我的实体的类型属性 例如 Long
那么问题是什么? 有没有办法从字符串“1234567890”检索格式为 1234567890 而不是 1.23456789E9 的 Double,因为默认情况下是由 Double.parseDouble(FormattedString) 完成的?
PD:我知道 DecimalFormat 的存在,但是考虑到使用此格式化程序会给我一个格式正确的字符串:“#######.E0”,但我真正需要的是什么是具有这种格式的 Double ,但是在执行 Double.parseDouble(FormattedString)
时,我会丢失这种格式。
希望我说得清楚并感谢您的帮助。
I am aware of the various posts floating out there with regards to the same issue.
Mine its a little bit different and it might be a little obvious, but I will need your comments.
I am currently using Hibernate Search and Lucene to Index entity properties.
I have a bunch of Double properties on my entities.
These entities using the default Bridges from Lucene (Bridge i.e the one in charge converting LongToString and StringToLong) are giving me troubles once the scientific notation starts to be used.
I am trying to show on DataTables on a .xhtml Credit and Debit amounts, their lenght can be as long as 18 digits, and their DataBase (DB2) type is BIGINT.
- I can not change the DataBase type
to Long for example. - I can not change either the Double
type attributes of my entities
either to for example Long
So whats the question?
Is there a way from a String say "1234567890" to retrieve a Double whose format is 1234567890 and not 1.23456789E9 as it is being done by default by Double.parseDouble(FormattedString)
?
PD: I am aware of the existance of DecimalFormat, however take into account using this formater will give me a String formated correctly say : "#######.E0" but what I really need is a Double with such format, however when doing Double.parseDouble(FormattedString)
I will loose such format.
Hope I was clear and thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的问题确实没有意义。 1234567890 与 1.23456789E9 的值相同,并且 double 代表其中之一,当且仅当它也代表另一个时。
不,没有办法构造一个
Double
以便它以某种方式显示。toStringDouble
的 code> 方法就是这样,无法更改。您唯一可以做的就是使用
DecimalFormat
或String.format
但正如您所注意到的,您总是会得到String< /代码>。
Your question doesn't really make sense. 1234567890 is the same value as 1.23456789E9 and a double represents one of them, if and only if it also represents the other.
No, there is no way to construct a
Double
so that it is displayed in a certain way. ThetoString
method forDouble
is what it is, and it can't be changed.The only thing you can do is to for instance use
DecimalFormat
orString.format
but as you've noted, you'll always end up with aString
.对 Lucene 一无所知,但 .xhtml 文档中永远不可能有 Double,它始终是字符串。 Double 没有格式,只有 Double 的字符串表示形式有。
Don't know nothing of Lucene, but you can never have a Double in a .xhtml Document it is always a characterstring. A Double doesn't have a Format, only a String representation of a Double has.
所以我终于找到了解决我的问题的方法。
在汇总了 aioobe 和 Jens Schauder 的说法后。我可以使用以下标签在 .xhtml 上动态设置文本格式:
感谢您向我澄清这些我模糊的基本内容:)
So I finally got the solution to my problem.
After rounding up what aioobe and Jens Schauder said. I am able to format the text dynamically on my .xhtml with the following tag:
Thanks for making clear to me these basic stuff I had blurred :)