Swift 国际化货币框架 Money,支持不同货币之间的计算和转换。支持比特币,也可以自定义货币类型。
示例代码:
import Money let money: Money = 100 print("I'll give \(money) to charity.”)以上代码,根据设置的区域不同,将输出不同的结果。
区域设置为美国时输出:
I'll give $100.00 to charity区域设置为英国时输出:
I'll give £100.00 to charity区域为中国时输出:
I'll give CN¥100.00 to charity初始化指定区域的货币:
let dollars = USD(minorUnits: 3250) let yuen = JPY(minorUnits: 3000) print(“You have \(dollars) and \(yuen)”)以上代码输出:
You have $32.50 and ¥3,000创建比特币:
let bitcoin: BTC = 0.1234_5678 print(“You have \(bitcoin)”)以上代码输出:
You have Ƀ0.12345678