From 3d47ac83d747a70e78eaaa523222b54158aef8ed Mon Sep 17 00:00:00 2001 From: Muraveiko Oleg U Date: Thu, 29 Oct 2020 17:16:40 +0300 Subject: [PATCH] Simplification of the code. https://pubs.opengroup.org/onlinepubs/009695399/functions/printf.html %05.2 where 0 - leading zero, 5 - full length with dot , 2 - after dot --- Project 02 - Stopwatch/Stopwatch/ViewController.swift | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Project 02 - Stopwatch/Stopwatch/ViewController.swift b/Project 02 - Stopwatch/Stopwatch/ViewController.swift index c5b1c165..bcf2175b 100644 --- a/Project 02 - Stopwatch/Stopwatch/ViewController.swift +++ b/Project 02 - Stopwatch/Stopwatch/ViewController.swift @@ -135,10 +135,7 @@ class ViewController: UIViewController, UITableViewDelegate { minutes = "0\((Int)(stopwatch.counter / 60))" } - var seconds: String = String(format: "%.2f", (stopwatch.counter.truncatingRemainder(dividingBy: 60))) - if stopwatch.counter.truncatingRemainder(dividingBy: 60) < 10 { - seconds = "0" + seconds - } + var seconds: String = String(format: "%05.2f", (stopwatch.counter.truncatingRemainder(dividingBy: 60))) label.text = minutes + ":" + seconds }