You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Derek Hohls <DH...@csir.co.za> on 2007/05/24 14:02:19 UTC

Formatting decimal values in a form

Still using Cocoon 2.1....
 
I need to format the "thousands" values in form's data value widget.
 
If I have:
<fd:datatype base="double">
    <fd:convertor type="formatting">
      <fd:patterns>
        <fd:pattern>###,###,###.###</fd:pattern>
      </fd:patterns>
    </fd:convertor>
</fd:datatype>
 
This works as expected eg. 5678901 is shown 5,678,901
The client would prefer space-separated values, but
 
<fd:datatype base="double">
    <fd:convertor type="formatting">
      <fd:patterns>
        <fd:pattern>### ### ###.###</fd:pattern>
      </fd:patterns>
    </fd:convertor>
</fd:datatype>
 
does not work -  5678901  stays 5678901 
 
The decimal format doc says:
"The prefixes, suffixes, and various symbols used for infinity, digits,

thousands separators, decimal separators, etc. may be set to 
arbitrary values, and they will appear properly during formatting. 
However, care must be taken that the symbols and strings do not 
conflict, or parsing will be unreliable."
http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormat.html 
 
Does this mean that spaces are a "conflicting symbol" - 
is there any way of getting this to work??
 
Thanks
Derek
 

-- 
This message is subject to the CSIR's copyright, terms and conditions and
e-mail legal notice. Views expressed herein do not necessarily represent the
views of the CSIR.
 
CSIR E-mail Legal Notice
http://mail.csir.co.za/CSIR_eMail_Legal_Notice.html 
 
CSIR Copyright, Terms and Conditions
http://mail.csir.co.za/CSIR_Copyright.html 
 
For electronic copies of the CSIR Copyright, Terms and Conditions and the CSIR
Legal Notice send a blank message with REQUEST LEGAL in the subject line to
CallCentre@csir.co.za.


This message has been scanned for viruses and dangerous content by MailScanner, 
and is believed to be clean.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Formatting decimal values in a form

Posted by Joerg Heinicke <jo...@gmx.de>.
On 25.05.2007 08:17, Derek Hohls wrote:

> after all the Cocoon docs *do* refer one to this page;
> which implies it *should* work (and does, partially, 
> because the "," separator works.)

The convertor only delegates everything to DecimalFormat. If it works 
there it will also work in the convertor. Cocoon does not do any parsing 
of the pattern since this might lead to even more unexpected/ 
contradictory results when the logic does not match the one in 
DecimalFormat.

The only calls that happen at the end in your case:

DecimalFormat decimalFormat = 
(DecimalFormat)NumberFormat.getNumberInstance(locale);
decimalFormat.applyPattern("### ### ###.###");

decimalFormat.format(value);

Try to find out if that simple code works for you (out of the CForms 
context). Also your pattern might be wrong. I'd try to change it, 
something like "# ##0.0".

If everything does not help think about writing your own Convertor + 
ConvertorBuilder, it's quite easy.

Joerg

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Formatting decimal values in a form

Posted by Derek Hohls <DH...@csir.co.za>.
Johannes
 
Maybe the code could be patched to include such a call;
after all the Cocoon docs *do* refer one to this page;
which implies it *should* work (and does, partially, 
because the "," separator works.)
 
In the meantime; whereabouts is the XSLT that I need to 
alter to get the formatting - bearing in mind its only on the
one form that I need to do it?  Or should I rather insert an 
extra step with a custom stylesheet into the pipeline 
*before* the  forms processing or *after* it??
 
Thanks
Derek

>>> Johannes Textor <jc...@gmx.de> 2007/05/24 06:07 PM >>>

Hi Derek,

>  
> The decimal format doc says:
> "The prefixes, suffixes, and various symbols used for infinity,
digits,
>
> thousands separators, decimal separators, etc. may be set to 
> arbitrary values, and they will appear properly during formatting. 
> However, care must be taken that the symbols and strings do not 
> conflict, or parsing will be unreliable."
> http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormat.html

>   
This is true but still does not mean that you can insert arbitrary 
characters between the "#". It means that when calling the 
setGroupingSeparator() method on a DecimalFormat object, you can choose

an arbitrary character. I am not aware of a method of setting the 
grouping separator on a "converter" element (doesn't seem possible 
guessing from the docs), so i'd suggest delegating this to the xsl
level 
where you can use the mighty "xsl:number" element.

Cheers,
Johannes



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org 
For additional commands, e-mail: users-help@cocoon.apache.org 



-- 
This message is subject to the CSIR's copyright, terms and conditions and
e-mail legal notice. Views expressed herein do not necessarily represent the
views of the CSIR.
 
CSIR E-mail Legal Notice
http://mail.csir.co.za/CSIR_eMail_Legal_Notice.html 
 
CSIR Copyright, Terms and Conditions
http://mail.csir.co.za/CSIR_Copyright.html 
 
For electronic copies of the CSIR Copyright, Terms and Conditions and the CSIR
Legal Notice send a blank message with REQUEST LEGAL in the subject line to
CallCentre@csir.co.za.


This message has been scanned for viruses and dangerous content by MailScanner, 
and is believed to be clean.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Formatting decimal values in a form

Posted by Johannes Textor <jc...@gmx.de>.
Hi Derek,

>  
> The decimal format doc says:
> "The prefixes, suffixes, and various symbols used for infinity, digits,
>
> thousands separators, decimal separators, etc. may be set to 
> arbitrary values, and they will appear properly during formatting. 
> However, care must be taken that the symbols and strings do not 
> conflict, or parsing will be unreliable."
> http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormat.html 
>   
This is true but still does not mean that you can insert arbitrary 
characters between the "#". It means that when calling the 
setGroupingSeparator() method on a DecimalFormat object, you can choose 
an arbitrary character. I am not aware of a method of setting the 
grouping separator on a "converter" element (doesn't seem possible 
guessing from the docs), so i'd suggest delegating this to the xsl level 
where you can use the mighty "xsl:number" element.

Cheers,
Johannes



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org