danthorpe / Money

Swift value types for working with money & currency
MIT License
933 stars 91 forks source link

unable to init money variable with custom decimal variable #48

Closed RajChanchal closed 8 years ago

RajChanchal commented 8 years ago

let money: GBP=34.0

this is possible

but this isn't

var myNumber:Double = 34.0 let money:GBP = myNumber

Error is cannot convert value of type Double to specified type 'GBP'

danthorpe commented 8 years ago

Yeah, Swift does not support automatic type casting.

For example you cannot do this either:

let aDouble: Double = 34.0
let anInteger: Int = aDouble

However, you can do this:

let aDouble: Double = 34.0
let anInteger = Int(aDouble)

And in the same way, you can also do this:

let myNumber: Double = 34.0
let money = GBP(myNumber)

This works for any MoneyType. Please re-open if you still have issues.