https://github.com/raed667/dinero
Dinero is a Rust port of Dinero.js (unstable)
https://github.com/raed667/dinero
dinero money rust rust-crate rust-lang rust-library rustlang
Last synced: 27 days ago
JSON representation
Dinero is a Rust port of Dinero.js (unstable)
- Host: GitHub
- URL: https://github.com/raed667/dinero
- Owner: raed667
- License: mit
- Created: 2022-10-12T19:46:12.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-11-28T10:27:51.000Z (over 2 years ago)
- Last Synced: 2025-04-23T23:48:19.698Z (27 days ago)
- Topics: dinero, money, rust, rust-crate, rust-lang, rust-library, rustlang
- Language: Rust
- Homepage: https://crates.io/crates/dinero
- Size: 45.9 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Dinero is a Rust port of Dinero.js
Dinero lets you create, calculate, and format money in Rust.
docs.rs/dinero---
## 📦 Install
```sh
$ cargo add dinero
```## ⚡️ Quick start
`Dinero` objects are minimal. The API is heavily inspired by `dinero.js` unless there is a more suitable Rust way to implement things.
```rust
use dinero::{api::add, currencies::USD, format::to_unit, Dinero};// Create a Dinero object of value 8.5 USD (the default scale for USD is 2)
let d1 = Dinero::new(850, USD, None);
// Create a Dinero object of value 5 USD with a custom scale 3
let d2 = Dinero::new(5000, USD, Some(3));// Add the 2 Dineros, the value is stored in the result Dinero without modifying d1 and d2
let result = add(&d1, &d2); // Similar API as Dinero.jslet result = d1 + d2; // Or you can use the standard operators
match result {
Ok(value) => println!("{} USD", to_unit(value, None, None)), // 13.5 USD
Err(_) => println!("Error adding d1+d2"),
}
```## 🦀 Disclaimer
I'm using this project to learn about Rust. And I'm working my way through the language and the ecosystem.
Consider the current version of Dinero **unstable**. There will _definitely_ be breaking changes.
## 📜 License
[MIT](LICENSE)