Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 NSLider,最小值为 0.6,最大值为 1。
我希望能够增加 0.1 并且没有诸如 0.6493 或 0.8435 之类的值
我将如何做到这一点?
我有这个功能
@IBAction func slider(sender : NSSlider) { var x: Double = sender.doubleValue // do something }
谢谢。
试试这种格式:
@IBAction func slider(sender : NSSlider) { let value = sender.value // "%.1f" show how many decimals you want to show let formatted = String(format: "%.1f", value) //formatted will be printed 0.X }