BigDecimal values and their default string presentation

Discuss all problems you have with Servoy here. It might help to mention the Servoy version and Operating System version you are using

BigDecimal values and their default string presentation

Postby rossent » Wed Oct 09, 2013 6:17 pm

Hi Servoy,

In our database, we have some columns defined as decimal(29,10) - that basically means, 29 significant digits of which 10 can be after the decimal point. This is a hard requirement for us.

The problem which we have is with the presentation of values which are loaded from the database from such columns. For example, if we have the following code:

utils.stringFormat("The values are %1$s, %2$s and %3$s", [column1, column2, column3])

and the following values in three columns of the type decimal(29,10) represented in servoy as NUMBER dataprovider

column1 = 0,
column2 = 10.25
column3 = 10.250001

When we load this in Servoy by reading the data from the database from an existing record, the result is:

"The values are 0E-10, 10.2500000000 and 10.2500010000"

and if the data is displayed in UI fields and the field is focused the values are 0.0000000000, 10.2500000000 and 10.2500010000

When these values are entered through the UI (for example, a new record is created and saved), the result is:

"The values are 0, 10.25 and 10.250001"

and if the data is displayed in UI fields and the field is focused the values are 0, 10.25 and 10.250001

What we need is the second result and we need it to be displayed like that always regardless where the data comes from (entered by the user or loaded from an existing record in the database)

It appears that Servoy is using different types for the data when loaded from the database (in that case, the data is actually BigDecimal) compared to when the data is entered by the user or through the code (in that case it appears to be Float or Double). Unfortunately no format mask (like %.4f or %.6f) works in that case (or the equivalent for the format property of the UI field) - we will either have to round and lose some significant digits or we will always have some trailing 0s. The only possible solution which I could come up with will be for Servoy when loading data from the database to use the stripTrailingZeros method of the BigDecimal class and use its result instead of using the data directly as is in the database. In our code we cannot do that because we do not know where the data which is currently in the JSRecord.columnX came from - the UI/code or from the database.

The "duality" behavior (BigDecimal when read from the database and Float/Double when written by the UI or code) is probably OK if the trailing 0s are stripped. I would prefer if the values provided by NUMBER dataproviders in Servoy always are of the same type regardless where the data comes from. As it is currently, however, it presents an unsolvable issue for us.

Is this a bug or a designed behavior? If this is by design, how can we resolve the issue which we are facing?
Rossen Totev
Argos Software
rossent
 
Posts: 288
Joined: Wed Dec 31, 2008 2:03 pm

Re: BigDecimal values and their default string presentation

Postby rossent » Wed Nov 06, 2013 9:11 am

Does anybody from Servoy have any input on this?
Rossen Totev
Argos Software
rossent
 
Posts: 288
Joined: Wed Dec 31, 2008 2:03 pm


Return to Discuss possible Issues and Bugs

Who is online

Users browsing this forum: No registered users and 17 guests