Post

Replies

Boosts

Views

Activity

Cannot convert value of type in extension
Hello folks, I'm currently trying to understand extensions and I'm looking for solution how to convert pow() inside my Double's extension. import Foundation extension Double { func rounded(to places: Int) -> Double { let precisionNumber = pow(10, places) var value = self value *= precisionNumber value.round() value /= precisionNumber return value } } var myDouble = 3.14159 print(myDouble.rounded(to: 2)) When I'm trying to multiply or divide "value" there is an error, because of their different types. pow() function imposes Decimal type on me. Is there any solution or better way to do this? Regards, misty
2
0
475
May ’23