Bug 274379 - DecimalTextRidget: allow setting a 'rounding-mode' when exceeding precision
Summary: DecimalTextRidget: allow setting a 'rounding-mode' when exceeding precision
Status: NEW
Alias: None
Product: Riena
Classification: RT
Component: ridget (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P4 enhancement (vote)
Target Milestone: 2.0.0   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-04-29 15:07 EDT by Elias Volanakis CLA
Modified: 2011-08-23 08:32 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Elias Volanakis CLA 2009-04-29 15:07:15 EDT
What should happen when the precision is less than the digits after comma on setText / updateFromModel ?

r.setPrecision(2);
r.updateFromModel(); // 3,1415 
results in?

Carsten:

Since it is considered to be an error in the application code I think instead of not showing the value a much better solution would be to throw an exception.

Another option would be to set a rounding mode on the Ridget like ROUND,FLOOR,CEIL,...?

Christian:

+1 for what carsten is saying, except that we should not have a rounding option at this point in time.....maybe later....

Ekke:

+1 for having a rounding option later - would be great for read-only or listing in table-columns etc

As discussed in this thread:
http://dev.eclipse.org/mhonarc/lists/riena-dev/msg00536.html
Comment 1 Elias Volanakis CLA 2009-04-29 15:15:03 EDT
This is something we will consider after 1.1.0.

The default mode should be 'throw exception'. Other modes should possible too (ROUDN, FLOOR, CEIL).

My preferred way of implementing this is do allow setting a rounding strategy (strategy pattern):

DecimalTextRidget.setRoundingStrategy(IRoundingStrategy s);
IRoundingStrategy:
  #X round(X value, int precision)
(X is the input/output type, not sure what this should be without investigating, leaving open for now)

This would allow the app developer to decide what to do based on the value and precision. The strategy would return the result of the rounding or throw an exception. If this is not set, the default strategy is to throw a new RuntimeException. The strategy would only be invoked if necessary (i.e. if the number of digits behind the decimal separator exceeds the precision).
Comment 2 Stefan Liebig CLA 2011-08-23 08:32:16 EDT
Bug 274378 (closely related to this) fulfills one of the requirements described in comment #1, it throws an exception if there are more fraction digits than allowed.

Lowering priority.