Swift 国际化货币框架 Money
Posted swift语言
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Swift 国际化货币框架 Money相关的知识,希望对你有一定的参考价值。
Swift 国际化货币框架 Money,支持不同货币之间的计算和转换。支持比特币,也可以自定义货币类型。
示例代码:
1 |
import Money |
2 |
3 |
let money: Money = 100 |
4 |
print("I'll give \(money) to charity.”) |
以上代码,根据设置的区域不同,将输出不同的结果。
区域设置为美国时输出:
1 |
I'll give $ 100.00 to charity |
区域设置为英国时输出:
1 |
I'll give £ 100.00 to charity |
区域为中国时输出:
1 |
I'll give CN¥ 100.00 to charity |
初始化指定区域的货币:
1 |
let dollars = USD(minorUnits: 3250 ) |
2 |
let yuen = JPY(minorUnits: 3000 ) |
3 |
4 |
print(“You have \(dollars) and \(yuen)”) |
以上代码输出:
1 |
You have $ 32.50 and ¥ 3 , 000 |
创建比特币:
1 |
let bitcoin: BTC = 0 .1234_5678 |
2 |
print(“You have \(bitcoin)”) |
以上代码输出:
< class="item viewSource" style="width: 16px;height: 16px;color: rgb(160, 160, 160) !important;display: block !important;float: left !important;margin-left: 8px !important;overflow: hidden !important;text-indent: -5000px !important;background-image: url("https://mmbiz.qpic.cn/mmbiz_png/825xC9EGQe0TYN8QVfmGwd35Mb4lp0KOiaboe780VPM2EbxjiaE9STzxhFavaYibfBGunNPjwNVs5quL9Tc9c53Fg/640?wx_fmt=png");background-repeat: no-repeat no-repeat !important;" title="view source">view source
< class="item printSource" style="width: 16px;height: 16px;color: rgb(160, 160, 160) !important;display: block !important;float: left !important;margin-left: 8px !important;overflow: hidden !important;text-indent: -5000px !important;background-image: url("https://mmbiz.qpic.cn/mmbiz_png/825xC9EGQe0TYN8QVfmGwd35Mb4lp0KOdTIaNOAj7zeMKApwOMNYzicH583ZYGHPJAvj4la7iav4PRiaJiafoyk5BQ/640?wx_fmt=png");background-repeat: no-repeat no-repeat !important;" title="print">print< class="item about" style="width: 16px;height: 16px;color: rgb(160, 160, 160) !important;display: block !important;float: left !important;margin-left: 8px !important;overflow: hidden !important;text-indent: -5000px !important;background-image: url("https://mmbiz.qpic.cn/mmbiz_png/825xC9EGQe0TYN8QVfmGwd35Mb4lp0KO7niakv6dYDn7rKNsZjaNaGcWFUW4TSlJjCSMdcYS2c1gxyERNpOxjkA/640?wx_fmt=png");background-repeat: no-repeat no-repeat !important;" title="?">?
1 |
You have Ƀ 0.12345678 |
开源代码主页:https://github.com/danthorpe/Money
文章来自:51swift.com
以上是关于Swift 国际化货币框架 Money的主要内容,如果未能解决你的问题,请参考以下文章