macro_rules! fixnum {
($value:literal, $precision:literal) => { ... };
}
Expand description
Macro to create fixed-point “literals”. Contains .into()
call inside so you can use it with your
From<FixedPoint>
wrapper types.
use derive_more::From;
use fixnum::{FixedPoint, typenum::U9, fixnum};
type Currency = FixedPoint<i64, U9>;
#[derive(From)]
struct Price(Currency);
#[derive(From)]
struct Deposit(Currency);
let p: Price = fixnum!(12.34, 9);
let d: Deposit = fixnum!(-0.4321, 9);
Probably you’d like to implement your own wrapper around this macro (see also examples
).
use fixnum::{FixedPoint, typenum::U9};
type Currency = FixedPoint<i64, U9>;
macro_rules! fp {
($val:literal) => {
fixnum::fixnum!($val, 9);
};
}
let c: Currency = fp!(12.34);