File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -63,8 +63,8 @@ extension XML.Formatter {
6363 return String ( describing: c)
6464 }
6565 }
66-
67- func format( fraction n: Double , maxDigits: Int ) -> String {
66+
67+ func format( fraction n: Double , maxDigits: Int ) -> String ? {
6868 assert ( n. sign == . plus)
6969
7070 let min = pow ( Double ( 10 ) , Double ( - maxDigits) ) - Double. ulpOfOne
@@ -74,6 +74,9 @@ extension XML.Formatter {
7474 }
7575
7676 let s = String ( format: " %. \( maxDigits) g " , n)
77+ if s == " 1 " {
78+ return nil
79+ }
7780 let idx = s. index ( s. startIndex, offsetBy: 1 )
7881 return String ( s [ idx..< s. endIndex] )
7982 }
@@ -92,8 +95,12 @@ extension XML.Formatter {
9295
9396 let integer = Int ( n. 0 )
9497 let fraction = format ( fraction: n. 1 , maxDigits: capped)
95-
96- return " \( sign) \( integer) \( fraction) "
98+
99+ if let fraction = fraction {
100+ return " \( sign) \( integer) \( fraction) "
101+ } else {
102+ return " \( sign) \( integer + 1 ) "
103+ }
97104 }
98105 }
99106}
You can’t perform that action at this time.
0 commit comments