Crates.io | overpunch |
lib.rs | overpunch |
version | 0.3.0 |
source | src |
created_at | 2024-10-15 23:38:00.480341 |
updated_at | 2024-11-03 04:41:41.95462 |
description | support for signed overpunch numbers |
homepage | https://github.com/capitalrx/overpunch |
repository | https://github.com/capitalrx/overpunch |
max_upload_size | |
id | 1410849 |
size | 22,330 |
A signed overpunch support library suitable for interacting with Decimal values.
$ cargo add overpunch
Alternatively, you can edit your Cargo.toml
directly and run cargo update
:
[dependencies]
overpunch = "0.3.0"
To parse signed overpunch numbers:
use overpunch::{convert_from_signed_format, extract};
use rust_decimal::Decimal;
let number = convert_from_signed_format("2258{", "s9(7)v99").unwrap();
assert_eq!(number, Decimal::from_str_exact("225.8").unwrap());
let number = extract("2258{", 2).unwrap();
assert_eq!(number, Decimal::from_str_exact("225.8").unwrap());
To format values to signed overpunch:
use overpunch::{convert_to_signed_format, format};
use rust_decimal::Decimal;
let formatted = convert_to_signed_format(Decimal::from_str_exact("225.8").unwrap(), "s9(7)v99").unwrap();
assert_eq!(formatted, "2258{");
let formatted = format(Decimal::from_str_exact("225.8").unwrap(), 2).unwrap();
assert_eq!(formatted, "2258{");