Re: [xslt] number-format() bug



Daniel Veillard wrote:
> 
> On Thu, Mar 22, 2001 at 01:56:00PM +0100, robert wrote:
> > While I'm at it, format-number() also contains a (rather serious) bug:
> > format-number(17.957, '#.0') gives '17.10' as output instead of '18.0'
> 
>   Hum, I hope Bjorn can have a look at it because I didn't tried to
> learn his code yet :-)

Patch enclosed for libxslt/numbers.c
Index: numbers.c
===================================================================
RCS file: /cvs/gnome/libxslt/libxslt/numbers.c,v
retrieving revision 1.9
diff -c -r1.9 numbers.c
*** numbers.c   2001/02/19 15:06:07     1.9
--- numbers.c   2001/03/22 19:03:35
***************
*** 730,735 ****
--- 730,736 ----
      int decimal_point;
      int is_percent;
      int is_permille;
+     double scale;

      buffer = xmlBufferCreate();
      if (buffer == NULL) {
***************
*** 855,860 ****
--- 856,863 ----
        number *= 1000.0;

      /* Integer part */
+     scale = pow(10.0, (double)(fraction_digits + fraction_hash));
+     number = (scale * number + 0.5) / scale;
      xsltNumberFormatDecimal(buffer, floor(number), (xmlChar)'0',
                            integer_digits, group, (xmlChar)',');

***************
*** 863,876 ****

        /* Fraction part */
        number -= floor(number);
!       number = number * pow(10.0, (double)(fraction_digits + fraction_hash));
        for (j = fraction_hash; j > 0; j--) {
            if (fmod(number, 10.0) >= 1.0)
                break; /* for */
            number /= 10.0;
        }
!       number = floor(0.5 + number);
!       xsltNumberFormatDecimal(buffer, number, (xmlChar)'0',
                                fraction_digits + j,
                                0, (xmlChar)0);
      }
--- 866,878 ----

        /* Fraction part */
        number -= floor(number);
!       number *= scale;
        for (j = fraction_hash; j > 0; j--) {
            if (fmod(number, 10.0) >= 1.0)
                break; /* for */
            number /= 10.0;
        }
!       xsltNumberFormatDecimal(buffer, floor(number), (xmlChar)'0',
                                fraction_digits + j,
                                0, (xmlChar)0);
      }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]