Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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.

  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.

like image 332
camiloqp Avatar asked Apr 06 '26 07:04

camiloqp


1 Answers

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.

like image 139
aioobe Avatar answered Apr 08 '26 20:04

aioobe