Bladeren bron

Minified numbers are now rounded to 2 decimal digits

Taddeus Kroes 11 jaren geleden
bovenliggende
commit
bed50c9bba
1 gewijzigde bestanden met toevoegingen van 5 en 2 verwijderingen
  1. 5 2
      stringify.ml

+ 5 - 2
stringify.ml

@@ -147,13 +147,16 @@ let string_of_stylesheet = cat "\n\n" string_of_statement
  *)
 
 let minify_num n =
+  (* Round numbers to at most 2 decimal digits *)
+  let round2 n = floor (100. *. n +. 0.5) /. 100. in
+
   if float_of_int (int_of_float n) = n then
     string_of_int (int_of_float n)
   else if n < 1.0 && n > -1.0 then
-    let s = string_of_float n in
+    let s = string_of_float (round2 n) in
     String.sub s 1 (String.length s - 1)
   else
-    string_of_float n
+    string_of_float (round2 n)
 
 let rec minify_expr = function
   | Concat values -> cat " " minify_expr values