The following example in Chapter 3 Types & Operations produces this error: Cannot invoke initializer for type ‘int’ with an argument list of type ‘(Decimal)’.
var integer: Int = 100
var decimal: Decimal = 12.5
integer = Int(decimal)
The following example in Chapter 3 Types & Operations produces this error: Cannot invoke initializer for type ‘int’ with an argument list of type ‘(Decimal)’.
var integer: Int = 100
var decimal: Decimal = 12.5
integer = Int(decimal)
Just use Double or Float type instead. I never used decimal type, and i find it useless, to be honest.
UPD:
Actually, you can only use it, because fields of NSDecimal are private. You can’t change private fields.
You are using the Decimal
type instead of the Double
one. Please go ahead and check out the chapter’s corresponding playground for the example’s correct and working version:
var integer: Int = 100 var decimal: Double = 12.5 integer = Int(decimal)
@alike010000 If you insist on using the Decimal type, then the following alternate solution will also work:
integer = Int(NSDecimalNumber(decimal: decimal))
The solution provided by @shogunkaramazov is completely fine, so you can choose either approach
All the best!
Thank you @syedfa for the alternative solution - much appreciated! :]
Anytime, and I’m sorry if I overstepped my bounds!
No problem and worries at all - don’t mention it - all good here after all! :]