Browse Source

I did not submit the right file on my last submission.
This patch corrects the printing of leading fractional
part 0s in Print("%f").

Signed-off-by: Nathan Blythe <nblythe@lgsinnovations.com>
Signed-off-by: Nigel Croxon <nigel.croxon@hpe.com>

Nigel Croxon 8 years ago
parent
commit
44d9ae1929
1 changed files with 21 additions and 2 deletions
  1. 21 2
      lib/print.c

+ 21 - 2
lib/print.c

@@ -1336,18 +1336,37 @@ FloatToString (
      */
     UINTN x = StrLen(Buffer);
     Buffer[x] = L'.';
+    x++;
 
 
     /*
-     * Fractional part.
+     * Keep fractional part.
      */
     float f = v - (float)i;
     if (f < 0) f = -f;
+
+
+    /*
+     * Leading fractional zeroes.
+     */
+    f *= 10.0;
+    while (   (f != 0)
+           && ((INTN)f == 0))
+    {
+      Buffer[x] = L'0';
+      x++;
+      f *= 10.0;
+    }
+
+
+    /*
+     * Fractional digits.
+     */
     while ((float)(INTN)f != f)
     {
       f *= 10;
     }
-    ValueToString(Buffer + x + 1, FALSE, (INTN)f);
+    ValueToString(Buffer + x, FALSE, (INTN)f);
     return;
 }