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

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

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