dinero: 微小的货币换算Go包

网友投稿 565 2022-11-05

dinero: 微小的货币换算Go包

dinero: 微小的货币换算Go包

dinero

dinero is a Go package for fetching exchange rates and converting between currencies. It aims to provide a simple interface and uses hippasus' ExchangeRates and decimal, which allows for higher precision when working with the values representing currency.

Installation

go get github.com/calmandniceperson/dinero

Examples

Converting a value in one currency to another

a := Amount{Value: decimal.NewFromFloat(5.245), Currency: USD}// ora := NewAmount(decimal.NewFromFloat(5.245), USD)res, _ := a.ConvertTo(EUR)// res contains the converted value as a decimal

Creating an amount from a float

a := NewAmountFromFloat(5.232, EUR)

Creating an amount from a string

a := NewAmountFromString("5423.65", JPY)

Creating a certain amount of a currency

u := USDa1 := u.Amount(decimal.NewFromFloat(25000))a2 := u.AmountFromFloat(7300.32)a3 := u.AmountFromString("200.09")

Printing an amount of a certain currency

a := Amount{decimal.NewFromFloat(450), JPY}println(a.String())

Dependencies

decimal

For testing

testify

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Linux之修改语言(语系)
下一篇:Linux之磁盘使用前为什么要进行格式化
相关文章

 发表评论

暂时没有评论,来抢沙发吧~