Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
-
None
Description
Due to a potential bug in BigDecimal there is a bug, when you use BigDecimal
with a NumberConverter.
Like
<tr:inputText value="#
" ...>
<tr:convertNumber />
</tr:inputText>
For instance, when the entered value is "333.111" the actual stored value is 333.1109999999999899955582804977893829345703125
There is a mathematic explanation for that in here:
http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems
Attachments
Issue Links
- is cloned by
-
MYFACES-1890 Numberconverter has issue with bigdecimal
- Closed
Here are two BigDecimals:
-new java.math.BigDecimal(new Double(333.111).toString())
-new java.math.BigDecimal(new Double(333.111).doubleValue())
the last is "wrong" in the sense of why the bug was filed...
The Trinidad Converter could do something like this, at the end of its
getAsObject() method:
...
ValueExpression ve = component.getValueExpression("value");
if(ve != null &&
BigDecimal.class.isAssignableFrom(ve.getType(context.getELContext())))
{
return (new BigDecimal(num.toString()));
}
...
However, this is (very) expensive, to execute on every time the getAsObject()
from the NumberConverter is called. Since it always goes to the last guy, in the expression.