# Decimal

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-base/utilities/struct-decimal/

**struct** · [`ferroui-base`](/docs/0.5.0/api/ferroui-base/) · v0.5.0

```rust
struct Decimal
```

An exact decimal number.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L41)

## Members

- [`ZERO`](#assoc_const-zero)
- [`ONE`](#assoc_const-one)
- [`MAX_VALUE`](#assoc_const-max_value)
- [`MIN_VALUE`](#assoc_const-min_value)
- [`from_parts`](#function-from_parts)
- [`mantissa`](#function-mantissa)
- [`scale`](#function-scale)
- [`is_sign_negative`](#function-is_sign_negative)
- [`is_zero`](#function-is_zero)
- [`max`](#function-max)
- [`min`](#function-min)
- [`checked_add`](#function-checked_add)
- [`checked_sub`](#function-checked_sub)
- [`checked_mul`](#function-checked_mul)
- [`checked_div`](#function-checked_div)
- [`to_f64`](#function-to_f64)
- [`to_f32`](#function-to_f32)
- [`round_to_integer`](#function-round_to_integer)
- [`from_f64`](#function-from_f64)
- [`from_f32`](#function-from_f32)
- [`try_from_f32`](#function-try_from_f32)
- [`try_from_f64`](#function-try_from_f64)
- [`parse`](#function-parse)
- [`try_parse`](#function-try_parse)
- [`parse_with`](#function-parse_with)
- [`try_parse_with`](#function-try_parse_with)
- [`to_string_with`](#function-to_string_with)
- [`to_string_provider`](#function-to_string_provider)

<a id="assoc_const-zero"></a>

### ZERO

```rust
const ZERO: Decimal
```

The number zero.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L45)

<a id="assoc_const-one"></a>

### ONE

```rust
const ONE: Decimal
```

The number one.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L48)

<a id="assoc_const-max_value"></a>

### MAX_VALUE

```rust
const MAX_VALUE: Decimal
```

The largest value: 79,228,162,514,264,337,593,543,950,335.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L51)

<a id="assoc_const-min_value"></a>

### MIN_VALUE

```rust
const MIN_VALUE: Decimal
```

The smallest value: -79,228,162,514,264,337,593,543,950,335.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L54)

<a id="function-from_parts"></a>

### from_parts

```rust
fn from_parts(mantissa: u128, scale: u8, negative: bool) -> Decimal
```

A decimal of `mantissa / 10^scale`, negated when `negative`.

Panics when the mantissa has more than 96 bits or the scale is
greater than 28.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L60)

<a id="function-mantissa"></a>

### mantissa

```rust
fn mantissa(self: &Self) -> u128
```

The 96-bit integer that, divided by `10^scale`, is the magnitude.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L70)

<a id="function-scale"></a>

### scale

```rust
fn scale(self: &Self) -> u8
```

The number of digits after the decimal point (0 to 28).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L76)

<a id="function-is_sign_negative"></a>

### is_sign_negative

```rust
fn is_sign_negative(self: &Self) -> bool
```

Whether the sign bit is set. Negative zero has it set and is equal to
zero.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L83)

<a id="function-is_zero"></a>

### is_zero

```rust
fn is_zero(self: &Self) -> bool
```

Whether the value is zero (of any scale and sign).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L89)

<a id="function-max"></a>

### max

```rust
fn max(self: Self, other: Decimal) -> Decimal
```

The larger of two values (C# `Math.Max`): of two equal values the
first, which matters for their scales.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L122)

<a id="function-min"></a>

### min

```rust
fn min(self: Self, other: Decimal) -> Decimal
```

The smaller of two values (C# `Math.Min`): of two equal values the
second, which matters for their scales.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L133)

<a id="function-checked_add"></a>

### checked_add

```rust
fn checked_add(self: Self, other: Decimal) -> Option<Decimal>
```

The sum, or `None` when it is out of range.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L143)

<a id="function-checked_sub"></a>

### checked_sub

```rust
fn checked_sub(self: Self, other: Decimal) -> Option<Decimal>
```

The difference, or `None` when it is out of range.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L149)

<a id="function-checked_mul"></a>

### checked_mul

```rust
fn checked_mul(self: Self, other: Decimal) -> Option<Decimal>
```

The product, or `None` when it is out of range. The scale is the sum
of the scales, rounded to 28 digits after the point when it is larger,
as the managed type multiplies.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L157)

<a id="function-checked_div"></a>

### checked_div

```rust
fn checked_div(self: Self, other: Decimal) -> Option<Decimal>
```

The quotient, or `None` when it is out of range. Panics when `other`
is zero.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L163)

<a id="function-to_f64"></a>

### to_f64

```rust
fn to_f64(self: &Self) -> f64
```

The nearest double-precision number (the explicit conversion of the
managed type to a double).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L179)

<a id="function-to_f32"></a>

### to_f32

```rust
fn to_f32(self: &Self) -> f32
```

The nearest single-precision number (the explicit conversion of the
managed type to a float): the double of the value, narrowed.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L199)

<a id="function-round_to_integer"></a>

### round_to_integer

```rust
fn round_to_integer(self: &Self) -> i128
```

The value rounded to an integer, midpoints to even (`Decimal.Round`
with no decimals, which the conversions of the managed runtime to the
integer types apply before their range check).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L206)

<a id="function-from_f64"></a>

### from_f64

```rust
fn from_f64(value: f64) -> Decimal
```

The decimal of a double-precision number, rounded to 15 significant
digits (the explicit conversion of a double to the managed type).

Panics when the number is not finite or is outside the value range.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L229)

<a id="function-from_f32"></a>

### from_f32

```rust
fn from_f32(value: f32) -> Decimal
```

The decimal of a single-precision number, rounded to 7 significant
digits (the explicit conversion of a float to the managed type).

Panics when the number is not finite or is outside the value range.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L237)

<a id="function-try_from_f32"></a>

### try_from_f32

```rust
fn try_from_f32(value: f32) -> Option<Decimal>
```

`from_f32`, with `None` where it panics.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L242)

<a id="function-try_from_f64"></a>

### try_from_f64

```rust
fn try_from_f64(value: f64) -> Option<Decimal>
```

`from_f64`, with `None` where it panics.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L307)

<a id="function-parse"></a>

### parse

```rust
fn parse(s: &str) -> Result<Decimal, NumberParseError>
```

Parses text of the invariant culture with the `Number` styles:
leading and trailing white space, a leading or trailing sign, a
decimal point and group separators.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L381)

<a id="function-try_parse"></a>

### try_parse

```rust
fn try_parse(s: &str) -> Option<Decimal>
```

`Decimal::parse` without the reason of a failure.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L387)

<a id="function-parse_with"></a>

### parse_with

```rust
fn parse_with(s: &str, styles: NumberStyles, provider: Option<&NumberFormatInfo>) -> Result<Decimal, NumberParseError>
```

Parses text with the given styles and format information (C#
`decimal.Parse(string, NumberStyles, IFormatProvider)`). Without a
provider the format information of the current culture is used.

Styles that are not defined, and the hexadecimal and binary styles,
are an error (`NumberParseError::InvalidStyle`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L397)

<a id="function-try_parse_with"></a>

### try_parse_with

```rust
fn try_parse_with(s: &str, styles: NumberStyles, provider: Option<&NumberFormatInfo>) -> Option<Decimal>
```

`Decimal::parse_with` without the reason of a failure.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L410)

<a id="function-to_string_with"></a>

### to_string_with

```rust
fn to_string_with(self: &Self, format: &str, provider: Option<&NumberFormatInfo>) -> Result<String, FormatError>
```

Formats the value with a standard or custom numeric format string
(C# `ToString(string, IFormatProvider)`). Without a provider the
format information of the current culture is used.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L417)

<a id="function-to_string_provider"></a>

### to_string_provider

```rust
fn to_string_provider(self: &Self, provider: &NumberFormatInfo) -> String
```

Formats the value in the general format with the given format
information (C# `ToString(IFormatProvider)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/utilities/decimal.rs#L426)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`ResourceKeyObject`](/docs/0.5.0/api/ferroui-base/controls/trait-resourcekeyobject/)
- [`PropertyValue`](/docs/0.5.0/api/ferroui-base/trait-propertyvalue/)
- [`AnyValue`](/docs/0.5.0/api/ferroui-base/trait-anyvalue/)
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `Borrow<T>`
- `BorrowMut<T>`
- `CloneToUninit`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ToOwned`
- `ToString`
- `ErasedDestructor`
- `IntoEither`
- `Clone`
- `Copy`
- `StructuralPartialEq`
- `PartialEq`
- `Eq`
- `PartialOrd`
- `Ord`
- `Hash`
- [`MarkupTyped`](/docs/0.5.0/api/ferroui-base/metadata/trait-markuptyped/)
- `Default`
- `Display`
- `Debug`
- `FromStr`
- `From<i8>`
- `From<i16>`
- `From<i32>`
- `From<i64>`
- `From<isize>`
- `From<u8>`
- `From<u16>`
- `From<u32>`
- `From<u64>`
- `From<usize>`
- `Neg`
- `Add`
- `Sub`
- `Div`
- `AddAssign`
- `SubAssign`
- [`ValueTypeRegistration`](/docs/0.5.0/api/ferroui-base/data/core/trait-valuetyperegistration/)

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
