diff --git a/Examples/MakerKit/Mission9_LCD/Sources/Mission9_LCD/LCD1602.swift b/Examples/MakerKit/Mission9_LCD/Sources/Mission9_LCD/LCD1602.swift index c5cab4a..ce2f776 100644 --- a/Examples/MakerKit/Mission9_LCD/Sources/Mission9_LCD/LCD1602.swift +++ b/Examples/MakerKit/Mission9_LCD/Sources/Mission9_LCD/LCD1602.swift @@ -243,9 +243,11 @@ final public class LCD1602 { mul *= 10 } let expandValue = Int(num * Float(mul)) - write(x: x, y: y, String(Float(expandValue) / Float(mul))) + let str = getFloatString(Float(expandValue) / Float(mul)) + write(x: x, y: y, str) } else { - write(x: x, y: y, String(num)) + let str = getFloatString(num) + write(x: x, y: y, str) } } } @@ -279,3 +281,10 @@ extension LCD1602 { } } } + + +func getFloatString(_ num: Float) -> String { + let int = Int(num) + let frac = Int((num - Float(int)) * 100) + return "\(int).\(frac)" +} \ No newline at end of file