Commits

Sébastien Ferré committed 79dbd1b

Correction in the printing of floats.

Comments (0)

Files changed (1)

         let exp e = if e = 0 then "" else "e" ^ string_of_int e in
 	let s =
           (if f < 0. then "-" else "") ^
-          if e = 1 then String.sub sm 0 1 ^ "." ^ String.sub sm 1 (l-1) ^ exp (p+l-1)
+          if e = 1 then
+	    if l >= 1 & p+l+2 <> 0 then String.sub sm 0 1 ^ "." ^ String.sub sm 1 (l-1) ^ exp (p+l-1)
+	    else "0.00" ^ sm ^ exp (p + l + 2)
           else if e = 2 then
-            if l >= 2 & p+l+1 <> 0 then String.sub sm 0 2 ^ "." ^ String.sub sm 1 (l-2) ^ exp (p+l-2)
+            if l >= 2 & p+l+1 <> 0 then String.sub sm 0 2 ^ "." ^ String.sub sm 2 (l-2) ^ exp (p+l-2)
             else "0.0" ^ sm ^ exp (p + l + 1)
           else
-            if l >= 3 & p+l <> 0 then String.sub sm 0 3 ^ "." ^ String.sub sm 1 (l-3) ^ exp (p+l-3)
+            if l >= 3 & p+l <> 0 then String.sub sm 0 3 ^ "." ^ String.sub sm 3 (l-3) ^ exp (p+l-3)
             else "0." ^ sm ^ exp (p + l) in
 	pp_print_string ff s
     | String s -> pp_print_string ff ("\"" ^ String.escaped s ^ "\"")