Comma and point ...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • asearle
    New Member
    • Sep 2006
    • 39

    Comma and point ...

    Hi everyone,

    I am on a project here in Germany and am having a tricky problem with decimal points which in Germany (and most other European countries) are represented by a comma instead.

    My XSLT transforms seem to work only with a point which isn't such a problem: I just tell the users that the 'point is the comma'. However as soon as we start transferring data (e.g. into Excel), the 'decimal points' confuse Excel which is set to expect the European 'comma' rather than the point.

    This means that we get a lot of fields/columns coming over as text when they should be numeric.

    To overcome the problem I have used all kinds of strange tricks like, for example, multiplying the number by 1000 (so that I get an integer) and then dividing it again to get the decimal (with either a point or a comma) but this type of solution is very clunky and can be error-prone.

    So has anyone else had this problem? Maybe there is a 'wrapping' syntax that I can use to force particular values to be recognised as numeric?

    Any tips or pointers to HOWTOs would be gratefully received.

    Regards,
    Alan Searle
  • asearle
    New Member
    • Sep 2006
    • 39

    #2
    To solve my problem with the decimal commas I have been investigating the command 'decimal format' ...

    <xsl:decimal-format name="european" decimal-separator="," grouping-separator="."/>

    My hope here is that I can switch to comma for the decimal and then both do mathematical operations on these values and display/export numeric values with commas.

    I have integrated the above syntax into my XSL templates but it does not seem to have any effect and, as before, values with '.' calculate correctly but values with ',' return NaN.

    I hope someone there has an idea on this one?

    Many thanks,
    Alan Searle

    Comment

    • asearle
      New Member
      • Sep 2006
      • 39

      #3
      Yippppeeee ... I found out how to do it:

      Here is a little example with decimal-format which I hope people find helpful.

      Regards,
      Alan Searle

      Example ...

      <xsl:decimal-format name="european" decimal-separator="," grouping-separator="." digit="D"/>
      <xsl:template match="/">
      <html>
      <body>
      ...
      <td align="right">< xsl:value-of select='format-number(price, "D,DD", "european") ' /></td>
      ...
      </xsl:for-each>
      ...
      <td align="right">< xsl:value-of select='format-number(sum(//price), "D,DD", "european") ' /></td>

      Comment

      Working...