pub fn scale_amount(
amount: u64,
from_decimals: u8,
to_decimals: u8,
) -> Result<u64, ProgramError>Expand description
Scale a token amount between different decimal precisions (floor).
Converts amount denominated in from_decimals to the equivalent
value in to_decimals. Uses u128 intermediate to prevent overflow.
ⓘ
let scaled = scale_amount(1_000_000, 6, 9)?; // USDC → SOL precision
assert_eq!(scaled, 1_000_000_000);