We can format output for double values with String Format:
Or we can use NumberFormatter Class (setting min and max number of digits after decimal separator):
let value = 3.1415 let formatValue = String(format:"%.2f", value) // 3.14
let formatter = NumberFormatter() formatter.numberStyle = NumberFormatter.Style.decimal formatter.roundingMode = NumberFormatter.RoundingMode.halfUp formatter.maximumFractionDigits = 2 formatter.minimumFractionDigits = 2 let roundedValue1 = formatter.string(from: 0.684) // 0.68 let roundedValue2 = formatter.string(from: 0.687) // 0.69 let roundedValue3 = formatter.string(from: 0.600) // 0.60
Really nice article. its really helpful me. Very interesting and good post thanks for sharing such a good blog.
ReplyDelete-Custom Web Design and Development
It was not an easy topic to elaborate in such a short span of time. Custom Website is such a complex topic but you made it easy to understand
ReplyDeleteThis post wowed me with its well-researched content and excellent writing. Because I was so involved in this book, I couldn't put it down. Your work and ability have wowed me. Thank you very much. Those who want to learn more about it may find it useful. Best Custom Websites
ReplyDeleteThank you very much for drawing my notice to this. Your blog is jam-packed with useful facts. Until I read that, I would have no idea. I'll come back for more fantastic material.
ReplyDeleteBest wishes, and good luck.
Web Design USA
Good content. I was looking for this type of content. Saved my time for further search.
ReplyDeleteYou should always provide that type of content. I appreciate your determination to give the students a good title.Custom Designed Websites
Amazing write-up! The blog was very informative. Keep it up!
ReplyDeleteCustom Website Development