You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by "Johan Compagner (JIRA)" <ji...@apache.org> on 2008/10/21 13:38:44 UTC

[jira] Closed: (WICKET-1882) The BigDecimalConverter is using the double constructor of BigDecimal instead of the String constructor

     [ https://issues.apache.org/jira/browse/WICKET-1882?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Johan Compagner closed WICKET-1882.
-----------------------------------

    Resolution: Fixed
      Assignee: Johan Compagner

BigDecimal uses the formatter (NumberFormat) to parse the string to a Number
That number if it is a double is then converted through to a BigDecimal with new BigDecimal(number.doubleValue()) yes
But that doesnt matter anymore because it is already a double then 

And we do test if the parsed number is a BigDecimal so what should happen is that your NumberFormat parses a BigDecimal instead of a Double
in 1.4 this cant be done. But in 1.5 DecimalFormat has this method:

   /**
     * Sets whether the {@link #parse(java.lang.String, java.text.ParsePosition)}
     * method returns <code>BigDecimal</code>. 
     * @see #isParseBigDecimal
     * @since 1.5
     */
    public void setParseBigDecimal(boolean newValue) {
        parseBigDecimal = newValue;
    }

so you just need to be sure that you call that on your number format that is returned by the converters:

public NumberFormat getNumberFormat(Locale locale) method.

i think i can do that in wicket 1.4 for you but not in 1.3

> The BigDecimalConverter is using the double constructor of BigDecimal instead of the String constructor
> -------------------------------------------------------------------------------------------------------
>
>                 Key: WICKET-1882
>                 URL: https://issues.apache.org/jira/browse/WICKET-1882
>             Project: Wicket
>          Issue Type: Wish
>          Components: wicket
>    Affects Versions: 1.3.4
>            Reporter: Koen Molkenboer
>            Assignee: Johan Compagner
>            Priority: Trivial
>
> The BigDecimalConverter is using the constructor BigDecimal(double val), but the results of this constructor can be somewhat unpredictable according to the Java doc:
> Translates a double into a BigDecimal. The scale of the BigDecimal is the smallest value such that (10scale * val) is an integer. 
> Note: the results of this constructor can be somewhat unpredictable. One might assume that new BigDecimal(.1) is exactly equal to .1, but it is actually equal to .1000000000000000055511151231257827021181583404541015625. This is so because .1 cannot be represented exactly as a double (or, for that matter, as a binary fraction of any finite length). Thus, the long value that is being passed in to the constructor is not exactly equal to .1, appearances notwithstanding. 
> The (String) constructor, on the other hand, is perfectly predictable: new BigDecimal(".1") is exactly equal to .1, as one would expect. Therefore, it is generally recommended that the (String) constructor be used in preference to this one.
> Could you change the BigDecimalConverter so it will use the String constructor when creating a new BigDecimal?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.