开发者

Can a Double be formatted without scientific notation?

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 usin开发者_如何学编程g 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.

  1. I can not change the DataBase type to Long for example.
  2. 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.


Is there a way from a String say "1234567890" to retrieve a Double whose value is 1234567890 and not 1.23456789E9 as it is being done by default by Double.parseDouble(FormattedString)?

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.

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(FormatedString) I will loose such format.

No, there is no way to construct a Double so that it is displayed in a certain way. The toString method for Double is what it is, and it can't be changed.

The only thing you can do is to for instance use DecimalFormat or String.format but as you've noted, you'll always end up with a String.


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.


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:

<h:outputText value="#{recordTable[column.property]}"
              rendered="#{column.header ne 'Details' and
                          column.header eq ('Total Credit Amount' or
                                            'Total Debit Amount')}">
              <f:convertNumber pattern="########"/>
</h:outputText>

Thanks for making clear to me these basic stuff I had blurred :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜