 extension String {
     func substringWithRange(_ start: Int, end: Int) -> String {
         var end = end
-        if start < 0 || start > self.characters.count {
+        if start < 0 || start > self.count {
             return ""
         }
-        else if end < 0 || end > self.characters.count {
-            end = self.characters.count
+        else if end < 0 || end > self.count {
+            end = self.count
         }
-        let range = self.characters.index(self.startIndex, offsetBy: start) ..< self.characters.index(self.startIndex, offsetBy: end)        
+        let range = self.index(self.startIndex, offsetBy: start) ..< self.index(self.startIndex, offsetBy: end)
         return String(self[range])
     }
 }

extension Double {
    func format(_ decimalPartLength: Int, minimumIntegerPartLength: Int = 0) -> String {
        let value = String(self)
        let components = value.characters
            .split() { $0 == "." }
            .map { String($0) }
        
        var integerPart = components.first ?? "0"
        
        let missingLeadingZeros = minimumIntegerPartLength - integerPart.characters.count
        if missingLeadingZeros > 0 {
            integerPart = stringWithZeros(missingLeadingZeros) + integerPart
        }

        }
        
        var decimalPlaces = components.last?.substringWithRange(0, end: decimalPartLength) ?? "0"
        let missingPlaceCount = decimalPartLength - decimalPlaces.count
        decimalPlaces += stringWithZeros(missingPlaceCount)
        
        return "\(integerPart).\(decimalPlaces)"
