]> git.kaiwu.me - quickjs.git/commitdiff
moved OOB in Intl.NumberFormat (#610 point 4)
authorFabrice Bellard <fabrice@bellard.org>
Tue, 10 Nov 2026 10:16:24 +0000 (11:16 +0100)
committerFabrice Bellard <fabrice@bellard.org>
Tue, 10 Nov 2026 10:16:24 +0000 (11:16 +0100)
intl/numberformat.c
tests/test_intl.js

index 60ef2f192f2a55bfbab6e49b52f5d370437002b0..8efe89fa0c43c1b4030c6a7d8427fdf3355f6ffb 100644 (file)
@@ -2425,9 +2425,13 @@ static JSValue intl_mv_format_scientific(JSContext *ctx, IntlMV *mv, JSNumberFor
     /* Integer part of mantissa */
     {
         char *int_buf = js_malloc(ctx, (size_t)digits_before + 1);
+        int n;
         if (!int_buf) goto sci_fail;
-        memcpy(int_buf, mv->digits, (size_t)digits_before);
-        int_buf[digits_before] = '\0';
+        n = min_int(digits_before, mv->num_digits);
+        memcpy(int_buf, mv->digits, n);
+        while (n < digits_before)
+            int_buf[n++] = '0';
+        int_buf[n] = '\0';
         dbuf_putstr(&db, int_buf);
         if (!JS_IsUndefined(parts))
             nf_add_part(ctx, parts, "integer", int_buf);
index 4b3b81bf1979b3bf6de0e48d6187bb702fa62d7c..b881fe93b9c6596b3339ba529b6e9c04cac1775f 100644 (file)
@@ -224,7 +224,8 @@ function test_numberFormat() {
     assert(new Intl.NumberFormat('en', { style: 'percent' }).format(0.5), "50%", "en percent");
     assert(new Intl.NumberFormat('en', { style: 'currency', currency: 'EUR' }).format(1234.56),
            "€1,234.56", "en EUR currency");
-
+    assert(new Intl.NumberFormat("en", { notation: "engineering" }).format(1e23), "100E21");
+    
     // de
     assert(new Intl.NumberFormat('de').format(1234567.89), "1.234.567,89", "de number");
     assert(new Intl.NumberFormat('de').format(1000000), "1.000.000", "de grouping");