Minor issue about the number of decimals for localized currency format

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Minor issue about the number of decimals for localized currency format

Jacopo Cappellato
I'd like your opinion about a (minor) issue in the way the
UtilFormatOut.formatCurrency(...) methods format currency numbers
according to the session locale:
if the amount has more fraction digits than the ones of the locale's
currency format the number is truncated (or approximated, I don't
remember); for example:

number: 50.012
currency format (for locale with 2 fraction digits): $50.01

Maybe this is correct but I'd prefer to have an option to get a more
precise representation of the figures: $50.012

In the attached patch I've modified the
UtilFormatOut.formatCurrency(...) methods so that now we have a new
parameter to specify the maximum number of fractional digits allowed;
I've also kept the original methods that simple call the new one and
work exactly as before.
I think I can commit this patch, is it ok?

But after this, there are three places where these methods are used:
* in the ftl ofbizCurrencyTransform
* in the FlexibleStringExpander
* in the form widget (for currency fields)

Should we also change them? For example:

Index: framework/widget/src/org/ofbiz/widget/form/ModelFormField.java
===================================================================
--- framework/widget/src/org/ofbiz/widget/form/ModelFormField.java
(revision 454108)
+++ framework/widget/src/org/ofbiz/widget/form/ModelFormField.java
(working copy)
@@ -1730,7 +1730,7 @@
                  }
                  try {
                      Double parsedRetVal = (Double)
ObjectType.simpleTypeConvert(retVal, "Double", null, locale, false);
-                    retVal = UtilFormatOut.formatCurrency(parsedRetVal,
isoCode, locale);
+                    retVal = UtilFormatOut.formatCurrency(parsedRetVal,
isoCode, locale, 10);
                  } catch (GeneralException e) {
                      String errMsg = "Error formatting currency value
[" + retVal + "]: " + e.toString();
                      Debug.logError(e, errMsg, module);



Thanks,

Jacopo

formatCurrency.zip (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Minor issue about the number of decimals for localized currency format

Si Chen-2
Jacopo,

The patch looks good to me.  I think that for the form widget,  
instead of defaulting to "10", how about default it to -1 as well, so  
we can use the locale's standard as a default?  The same of course  
for ofbizCurrency.  Then later somebody can implement a tag or  
attribute to control the decimal precision.

On Oct 11, 2006, at 10:59 AM, Jacopo Cappellato wrote:

> I'd like your opinion about a (minor) issue in the way the  
> UtilFormatOut.formatCurrency(...) methods format currency numbers  
> according to the session locale:
> if the amount has more fraction digits than the ones of the  
> locale's currency format the number is truncated (or approximated,  
> I don't remember); for example:
>
> number: 50.012
> currency format (for locale with 2 fraction digits): $50.01
>
> Maybe this is correct but I'd prefer to have an option to get a  
> more precise representation of the figures: $50.012
>
> In the attached patch I've modified the UtilFormatOut.formatCurrency
> (...) methods so that now we have a new parameter to specify the  
> maximum number of fractional digits allowed; I've also kept the  
> original methods that simple call the new one and work exactly as  
> before.
> I think I can commit this patch, is it ok?
>
> But after this, there are three places where these methods are used:
> * in the ftl ofbizCurrencyTransform
> * in the FlexibleStringExpander
> * in the form widget (for currency fields)
>
> Should we also change them? For example:
>
> Index: framework/widget/src/org/ofbiz/widget/form/ModelFormField.java
> ===================================================================
> --- framework/widget/src/org/ofbiz/widget/form/ModelFormField.java  
> (revision 454108)
> +++ framework/widget/src/org/ofbiz/widget/form/ModelFormField.java  
> (working copy)
> @@ -1730,7 +1730,7 @@
>                  }
>                  try {
>                      Double parsedRetVal = (Double)  
> ObjectType.simpleTypeConvert(retVal, "Double", null, locale, false);
> -                    retVal = UtilFormatOut.formatCurrency
> (parsedRetVal, isoCode, locale);
> +                    retVal = UtilFormatOut.formatCurrency
> (parsedRetVal, isoCode, locale, 10);
>                  } catch (GeneralException e) {
>                      String errMsg = "Error formatting currency  
> value [" + retVal + "]: " + e.toString();
>                      Debug.logError(e, errMsg, module);
>
>
>
> Thanks,
>
> Jacopo
> <formatCurrency.zip>

Best Regards,

Si
[hidden email]



Reply | Threaded
Open this post in threaded view
|

Re: Minor issue about the number of decimals for localized currency format

David E Jones-2
In reply to this post by Jacopo Cappellato

Jacopo,

Yes, I think this is fine. I guess the only alternative would be to  
not use this when more flexibility is needed, which is a pain and  
makes it significantly less helpful.

So, yes, I'd say go for it.

-David



On Oct 11, 2006, at 6:59 PM, Jacopo Cappellato wrote:

> I'd like your opinion about a (minor) issue in the way the  
> UtilFormatOut.formatCurrency(...) methods format currency numbers  
> according to the session locale:
> if the amount has more fraction digits than the ones of the  
> locale's currency format the number is truncated (or approximated,  
> I don't remember); for example:
>
> number: 50.012
> currency format (for locale with 2 fraction digits): $50.01
>
> Maybe this is correct but I'd prefer to have an option to get a  
> more precise representation of the figures: $50.012
>
> In the attached patch I've modified the UtilFormatOut.formatCurrency
> (...) methods so that now we have a new parameter to specify the  
> maximum number of fractional digits allowed; I've also kept the  
> original methods that simple call the new one and work exactly as  
> before.
> I think I can commit this patch, is it ok?
>
> But after this, there are three places where these methods are used:
> * in the ftl ofbizCurrencyTransform
> * in the FlexibleStringExpander
> * in the form widget (for currency fields)
>
> Should we also change them? For example:
>
> Index: framework/widget/src/org/ofbiz/widget/form/ModelFormField.java
> ===================================================================
> --- framework/widget/src/org/ofbiz/widget/form/ModelFormField.java  
> (revision 454108)
> +++ framework/widget/src/org/ofbiz/widget/form/ModelFormField.java  
> (working copy)
> @@ -1730,7 +1730,7 @@
>                  }
>                  try {
>                      Double parsedRetVal = (Double)  
> ObjectType.simpleTypeConvert(retVal, "Double", null, locale, false);
> -                    retVal = UtilFormatOut.formatCurrency
> (parsedRetVal, isoCode, locale);
> +                    retVal = UtilFormatOut.formatCurrency
> (parsedRetVal, isoCode, locale, 10);
>                  } catch (GeneralException e) {
>                      String errMsg = "Error formatting currency  
> value [" + retVal + "]: " + e.toString();
>                      Debug.logError(e, errMsg, module);
>
>
>
> Thanks,
>
> Jacopo
> <formatCurrency.zip>