Function format_zats_as_zec

Source
pub fn format_zats_as_zec(amount: impl Into<u64>) -> String
Expand description

Formats an amount in zatoshi (smallest Zcash unit) as a human-readable ZEC value.

This function converts a zatoshi amount to a ZEC amount with the proper decimal places. There are 100,000,000 zatoshi in 1 ZEC, similar to how there are 100,000,000 satoshi in 1 Bitcoin.

§Arguments

  • amount - A zatoshi amount that can be converted to u64

§Returns

A string with the formatted ZEC amount, with the prefix “ZEC” (e.g., “ZEC 1.23456789”)

§Examples

// 1 ZEC = 100_000_000 zatoshi
assert_eq!(format_zats_as_zec(100_000_000_u64), "ZEC 1.0");
 
// Format partial ZEC amounts
assert_eq!(format_zats_as_zec(123_456_789_u64), "ZEC 1.23456789");
 
// Trailing zeros are trimmed
assert_eq!(format_zats_as_zec(100_000_000_000_u64), "ZEC 1000.0");