Keyboard shortcuts

Press or to navigate between chapters

Press ? to show this help

Press Esc to hide this help

DecimalTrait

Fully qualified path: alexandria_math::decimal::DecimalTrait

pub trait DecimalTrait

Trait functions

from_int

Create a decimal from an integer part

Fully qualified path: alexandria_math::decimal::DecimalTrait::from_int

fn from_int(int_part: u64) -> Decimal

from_parts

Create a decimal from integer and decimal parts (user-friendly) int_part: integer portion (e.g., 3 for 3.35) decimal_part: decimal portion as integer (e.g., 35 for 0.35) Example: from_parts(3, 35) creates 3.35, from_parts(56, 678) creates 56.678

Fully qualified path: alexandria_math::decimal::DecimalTrait::from_parts

fn from_parts(int_part: u64, decimal_part: u64) -> Decimal

from_raw_parts

Create a decimal from integer and raw fractional parts (internal use) frac_part should be in range [0, 10^18) - raw DECIMAL_SCALE units

Fully qualified path: alexandria_math::decimal::DecimalTrait::from_raw_parts

fn from_raw_parts(int_part: u64, frac_part: u64) -> Decimal

from_raw_parts_signed

Create a signed decimal from integer and raw fractional parts (internal use) frac_part should be in range [0, 10^18) - raw DECIMAL_SCALE units

Fully qualified path: alexandria_math::decimal::DecimalTrait::from_raw_parts_signed

fn from_raw_parts_signed(int_part: u64, frac_part: u64, is_negative: bool) -> Decimal

from_felt

Create a decimal from a felt252 (treating it as integer) Note: This method treats all felt252 values as positive For negative values, use from_felt_signed or other constructors

Fully qualified path: alexandria_math::decimal::DecimalTrait::from_felt

fn from_felt(value: felt252) -> Decimal

from_felt_signed

Create a signed decimal from a felt252

Fully qualified path: alexandria_math::decimal::DecimalTrait::from_felt_signed

fn from_felt_signed(value: felt252, is_negative: bool) -> Decimal

from_parts_signed

Create a signed decimal from integer and decimal parts (user-friendly) int_part: integer portion (e.g., 3 for 3.35) decimal_part: decimal portion as integer (e.g., 35 for 0.35) is_negative: sign of the number Example: from_parts_signed(3, 35, true) creates -3.35

Fully qualified path: alexandria_math::decimal::DecimalTrait::from_parts_signed

fn from_parts_signed(int_part: u64, decimal_part: u64, is_negative: bool) -> Decimal

int_part

Get the integer part

Fully qualified path: alexandria_math::decimal::DecimalTrait::int_part

fn int_part(self: @Decimal) -> u64

frac_part

Get the fractional part

Fully qualified path: alexandria_math::decimal::DecimalTrait::frac_part

fn frac_part(self: @Decimal) -> u64

is_negative

Get the sign (true if negative)

Fully qualified path: alexandria_math::decimal::DecimalTrait::is_negative

fn is_negative(self: @Decimal) -> bool

to_felt

Convert to felt252 (truncates fractional part)

Fully qualified path: alexandria_math::decimal::DecimalTrait::to_felt

fn to_felt(self: @Decimal) -> felt252

add

Add two decimals

Fully qualified path: alexandria_math::decimal::DecimalTrait::add

fn add(self: @Decimal, other: @Decimal) -> Decimal

sub

Subtract two decimals

Fully qualified path: alexandria_math::decimal::DecimalTrait::sub

fn sub(self: @Decimal, other: @Decimal) -> Decimal

mul

Multiply two decimals

Fully qualified path: alexandria_math::decimal::DecimalTrait::mul

fn mul(self: @Decimal, other: @Decimal) -> Decimal

div

Divide two decimals

Fully qualified path: alexandria_math::decimal::DecimalTrait::div

fn div(self: @Decimal, other: @Decimal) -> Decimal

to_string

Convert to string representation

Fully qualified path: alexandria_math::decimal::DecimalTrait::to_string

fn to_string(self: @Decimal) -> ByteArray

from_string

Parse a decimal from string (basic implementation)

Fully qualified path: alexandria_math::decimal::DecimalTrait::from_string

fn from_string(s: ByteArray) -> Option<Decimal>