#ibm #mainframe #cobol #parser

overpunch

support for signed overpunch numbers

3 releases (breaking)

0.3.0 Nov 3, 2024
0.2.0 Oct 16, 2024
0.1.0 Oct 15, 2024

#355 in Finance

Download history 297/week @ 2024-10-14 48/week @ 2024-10-21 253/week @ 2024-10-28 116/week @ 2024-11-04 68/week @ 2024-11-11

501 downloads per month

MIT license

10KB
142 lines

Overpunch   Build Status Latest Version

A signed overpunch support library suitable for interacting with Decimal values.

Installing

$ cargo add overpunch

Alternatively, you can edit your Cargo.toml directly and run cargo update:

[dependencies]
overpunch = "0.3.0"

Usage

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{");

Dependencies

~0.9–1.5MB
~32K SLoC