Skip to content

Commit

Permalink
Update for Embedded Swift
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Liu <andy@madmachine.io>
  • Loading branch information
andy0808 committed Sep 24, 2024
1 parent a3489e5 commit 99c8d6c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Examples/MakerKit/Mission9_LCD/Sources/Mission9_LCD/LCD1602.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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)"
}

0 comments on commit 99c8d6c

Please sign in to comment.