pub fn validate_amount_decimals(
amount: f64,
currency: &str,
) -> Result<(), ParseError>
Expand description
Validate amount decimal precision for a specific currency (C03 validation)
SWIFT network validation rule C03 requires that the number of decimal places in an amount must not exceed the maximum allowed for the currency.
§Arguments
amount
- The amount value to validatecurrency
- ISO 4217 currency code
§Returns
Ok(()) if decimal precision is valid, Err(ParseError) if exceeds limit
§Errors
Returns ParseError::InvalidFormat with C03 error if decimal precision exceeded
§Examples
use swift_mt_message::fields::swift_utils::validate_amount_decimals;
validate_amount_decimals(100.50, "USD").unwrap(); // Ok - 2 decimals allowed
validate_amount_decimals(100.0, "JPY").unwrap(); // Ok - 0 decimals allowed
assert!(validate_amount_decimals(100.50, "JPY").is_err()); // JPY allows 0 decimals only
assert!(validate_amount_decimals(100.5055, "BHD").is_err()); // BHD allows 3 decimals max