Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » AbstractDoubleColumn: rounding decimal values(decimal values like 0.25 round to 0.2, which isn't mathematical correct)
AbstractDoubleColumn: rounding decimal values [message #909616] Fri, 07 September 2012 12:30 Go to next message
Birgit Körschgen is currently offline Birgit KörschgenFriend
Messages: 1
Registered: September 2012
Junior Member
It seems that the method org.eclipse.scout.rt.client.ui.basic.table.columns.AbstractDoubleColumn.decorateCellInternal(Cell cell, ITableRow row) doesn't round decimal values correctly.
As an example: when you have a value 0.25 and maxFractionDigits set on 1, then you get 0.2. On my opinion it should be 0.3 (which would be mathematical correct).

The reason for this seems to be that java uses RoundingMode.HALF_EVEN as default (see also the javadoc for DecimalFormat and RoundingMode). This rounding mode "rounds towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor".

The following little program visualizes this:

public class XXX {
public static void main(String[] args) {
DecimalFormat f = (DecimalFormat) NumberFormat.getNumberInstance();





So, why can't we do it with mathematic correctness?
Re: AbstractDoubleColumn: rounding decimal values [message #909631 is a reply to message #909616] Fri, 07 September 2012 12:50 Go to previous messageGo to next message
Ivan Motsch is currently offline Ivan MotschFriend
Messages: 123
Registered: March 2010
Senior Member
Thanks for the post.

This is about the debate "mathematical" correctness or "financial" correctness in java.
Basically scout cannot decide which one is better since it depends on the business logic of the project using it.
Therefore the default in scout is to use java "as is". And java uses the default ROUND_EVEN.

When thinking about setting the explicit ROUND_UP default in eclipse scout, there are two major issues.
1) scout then uses a different default than java and programmers might run into an issue where there are inconsistent behaviours.

2) we break existing functionality of end-users and developers that rely on that current default.

However also java is not very consistent: Math.round makes an implicit ROUND_UP.

Possible solution for scout to find a default value for runding would be
1. using a system property
2. using an osgi context service
3. overriding AbstractDoubleColumn#getNumberFormat

solution 1 and 2 require a scout change and depending on the customer requirements they are too global or too specific.

solution 1 would be my preferred one, since it defines a global JAVA default for rounding that could be used in all parts of the java application, not just scout ad eclipse.

solution 2 includes a service call for every number formatting and is very expensive.

solution 3 can be done by you at once, just add an override.

For solution 1 you would have to create bugzilla. Solution 3 is in place already.
Re: AbstractDoubleColumn: rounding decimal values [message #1220550 is a reply to message #909616] Thu, 12 December 2013 14:17 Go to previous messageGo to next message
Adrian Sacchi is currently offline Adrian SacchiFriend
Messages: 7
Registered: January 2013
Junior Member
Scout 3.10 introduces RoundingMode as property for all number fields and columns. The default for all decimal fields and columns is ROUND_HALF_UP.

Re: AbstractDoubleColumn: rounding decimal values [message #1220762 is a reply to message #1220550] Fri, 13 December 2013 13:12 Go to previous message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1206
Registered: October 2011
Senior Member
This is great work!

Can you also mention the new property on the field and colum pages:
* DoubleField
* BigDecimalField
* DoubleColumn
* BigDecimalColumn

Maybe with a note indicating that we support for version > 3.10.0:
{{important|Required version|The API described here requires version 3.10.0 or bigger.}}

Thank you in advance.
Previous Topic:How To add Tabs to TabBox programmatically
Next Topic:Custom Logger
Goto Forum:

Current Time: Mon Jan 23 17:16:15 GMT 2017

Powered by FUDForum. Page generated in 0.08462 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software