You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by "Matthias Weßendorf (JIRA)" <de...@myfaces.apache.org> on 2008/06/17 03:05:45 UTC
[jira] Created: (TRINIDAD-1124) numberconverter has issue with
bigdecimal
numberconverter has issue with bigdecimal
-----------------------------------------
Key: TRINIDAD-1124
URL: https://issues.apache.org/jira/browse/TRINIDAD-1124
Project: MyFaces Trinidad
Issue Type: Bug
Reporter: Matthias Weßendorf
Assignee: Matthias Weßendorf
Due to a potential bug in BigDecimal there is a bug, when you use BigDecimal
with a NumberConverter.
Like
<tr:inputText value="#{bean.number}" ...>
<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
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (TRINIDAD-1124) numberconverter has issue with
bigdecimal
Posted by "Ed Burns (JIRA)" <de...@myfaces.apache.org>.
[ https://issues.apache.org/jira/browse/TRINIDAD-1124?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12606900#action_12606900 ]
Ed Burns commented on TRINIDAD-1124:
------------------------------------
Hello Matthias,
I made the change you suggested to my NumberConverter, but I cannot reproduce the error you're describing.
Here is my testcase:
Converter converter = application.createConverter("javax.faces.Number");
String stringToConvert = "333.111";
Object obj = converter.getAsObject(getFacesContext(), text,
stringToConvert);
assertTrue(obj instanceof java.lang.Number);
String str = converter.getAsString(getFacesContext(), text, obj);
assertTrue(str.equals(stringToConvert));
The obj I get back is now a BigDecimal, after making your change, however, its value is still 333.111, not 333.1109999999999899955582804977893829345703125 .
How can I reproduce this?
> numberconverter has issue with bigdecimal
> -----------------------------------------
>
> Key: TRINIDAD-1124
> URL: https://issues.apache.org/jira/browse/TRINIDAD-1124
> Project: MyFaces Trinidad
> Issue Type: Bug
> Reporter: Matthias Weßendorf
> Assignee: Matthias Weßendorf
> Fix For: 1.0.9-core, 1.2.9-core
>
>
> Due to a potential bug in BigDecimal there is a bug, when you use BigDecimal
> with a NumberConverter.
> Like
> <tr:inputText value="#{bean.number}" ...>
> <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
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (TRINIDAD-1124) numberconverter has issue with
bigdecimal
Posted by "Matthias Weßendorf (JIRA)" <de...@myfaces.apache.org>.
[ https://issues.apache.org/jira/browse/TRINIDAD-1124?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12606956#action_12606956 ]
Matthias Weßendorf commented on TRINIDAD-1124:
----------------------------------------------
Hi Ed,
the testcase doesn't reproduce it. Here is why:
Converter converter = application.createConverter("javax.faces.Number");
...
converter.getAsObject(getFacesContext(), text,
stringToConvert);
...
BEFORE your change, it would return a Double, with the Value 333.111, which is correct.
Now, it returns a BigDecimal, which is more correct, but still the value is 333.111 (as wanted)
But... when the bean value is actually BigDecimal, it (the Double object) would be converted into a BigDecmial,
by EL engine with something like:
new BigDecimal(doubleObjectReturnedFromTheConverter.doubleValue());
this... would cause the problem. Therefore I provided these two simple tests in my first comment:
-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... (means a value like 333.110984654754...)
So you can reproduce it an application such as:
<tr:inputText value="#{bean.number}" ...>
<tr:convertNumber />
</tr:inputText>
Where "number" property is actually BigDecimal and... the converter actually returns a double (which WAS the case).
Is this more clear ?
> numberconverter has issue with bigdecimal
> -----------------------------------------
>
> Key: TRINIDAD-1124
> URL: https://issues.apache.org/jira/browse/TRINIDAD-1124
> Project: MyFaces Trinidad
> Issue Type: Bug
> Reporter: Matthias Weßendorf
> Assignee: Matthias Weßendorf
> Fix For: 1.0.9-core, 1.2.9-core
>
>
> Due to a potential bug in BigDecimal there is a bug, when you use BigDecimal
> with a NumberConverter.
> Like
> <tr:inputText value="#{bean.number}" ...>
> <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
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (TRINIDAD-1124) numberconverter has issue with
bigdecimal
Posted by "Matthias Weßendorf (JIRA)" <de...@myfaces.apache.org>.
[ https://issues.apache.org/jira/browse/TRINIDAD-1124?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12605471#action_12605471 ]
Matthias Weßendorf commented on TRINIDAD-1124:
----------------------------------------------
I now noticed that there is a setParseBigDecimal( bool ) on DecimalFormat (which is used).
Setting this to true is the fix. It may be a little bit expensive, but at the end, we are safe with this fix
> numberconverter has issue with bigdecimal
> -----------------------------------------
>
> Key: TRINIDAD-1124
> URL: https://issues.apache.org/jira/browse/TRINIDAD-1124
> Project: MyFaces Trinidad
> Issue Type: Bug
> Reporter: Matthias Weßendorf
> Assignee: Matthias Weßendorf
>
> Due to a potential bug in BigDecimal there is a bug, when you use BigDecimal
> with a NumberConverter.
> Like
> <tr:inputText value="#{bean.number}" ...>
> <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
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (TRINIDAD-1124) numberconverter has issue with
bigdecimal
Posted by "Matthias Weßendorf (JIRA)" <de...@myfaces.apache.org>.
[ https://issues.apache.org/jira/browse/TRINIDAD-1124?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12605469#action_12605469 ]
Matthias Weßendorf commented on TRINIDAD-1124:
----------------------------------------------
Got feedback from Blake Sullivan:
I believe that the source of the problem is that we are always converting to
Double, which can lose information. The safe thing to do is to use
BigDecimal as our intermediate type, which is lossless.
> numberconverter has issue with bigdecimal
> -----------------------------------------
>
> Key: TRINIDAD-1124
> URL: https://issues.apache.org/jira/browse/TRINIDAD-1124
> Project: MyFaces Trinidad
> Issue Type: Bug
> Reporter: Matthias Weßendorf
> Assignee: Matthias Weßendorf
>
> Due to a potential bug in BigDecimal there is a bug, when you use BigDecimal
> with a NumberConverter.
> Like
> <tr:inputText value="#{bean.number}" ...>
> <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
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Resolved: (TRINIDAD-1124) numberconverter has issue with
bigdecimal
Posted by "Matthias Weßendorf (JIRA)" <de...@myfaces.apache.org>.
[ https://issues.apache.org/jira/browse/TRINIDAD-1124?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Matthias Weßendorf resolved TRINIDAD-1124.
------------------------------------------
Resolution: Fixed
Fix Version/s: 1.2.9-core
1.0.9-core
> numberconverter has issue with bigdecimal
> -----------------------------------------
>
> Key: TRINIDAD-1124
> URL: https://issues.apache.org/jira/browse/TRINIDAD-1124
> Project: MyFaces Trinidad
> Issue Type: Bug
> Reporter: Matthias Weßendorf
> Assignee: Matthias Weßendorf
> Fix For: 1.0.9-core, 1.2.9-core
>
>
> Due to a potential bug in BigDecimal there is a bug, when you use BigDecimal
> with a NumberConverter.
> Like
> <tr:inputText value="#{bean.number}" ...>
> <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
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (TRINIDAD-1124) numberconverter has issue with
bigdecimal
Posted by "Matthias Weßendorf (JIRA)" <de...@myfaces.apache.org>.
[ https://issues.apache.org/jira/browse/TRINIDAD-1124?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12605468#action_12605468 ]
Matthias Weßendorf commented on TRINIDAD-1124:
----------------------------------------------
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.
> numberconverter has issue with bigdecimal
> -----------------------------------------
>
> Key: TRINIDAD-1124
> URL: https://issues.apache.org/jira/browse/TRINIDAD-1124
> Project: MyFaces Trinidad
> Issue Type: Bug
> Reporter: Matthias Weßendorf
> Assignee: Matthias Weßendorf
>
> Due to a potential bug in BigDecimal there is a bug, when you use BigDecimal
> with a NumberConverter.
> Like
> <tr:inputText value="#{bean.number}" ...>
> <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
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.