Currency Currency
Currency Currency
DocFX + Singulink = ♥

Search Results for

    Method Allocate

    Allocate(int)

    Allocates this value into the specified number of equal parts that are valid amounts under the currency's RoundingPolicy, distributing any remainder so that the parts always sum to this value rounded to the policy.

    Declaration
    public ImmutableArray<MonetaryValue> Allocate(int count)
    Parameters
    Type Name Description
    int count

    The number of parts to allocate the value into.

    Returns
    Type Description
    ImmutableArray<MonetaryValue>
    Remarks

    The value is first rounded to the policy using ToEven rounding, and the parts always sum exactly to that rounded value. The remainder that results from rounding the individual parts down to the policy's smallest unit is distributed one unit at a time to the parts that lost the largest fraction (the "largest remainder" method), with ties resolved in favor of earlier parts. For equal allocations this means earlier parts receive the extra units, i.e. USD 100.00 allocated into 3 parts yields 34.34, 33.33 and 33.33.

    Negative values are allocated the same way as their absolute value with the parts negated. Parts with a zero ratio are always zero. A default value is allocated into default values.

    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    count is less than 1.

    Allocate(params ReadOnlySpan<decimal>)

    Allocates this value into parts proportional to the specified ratios that are valid amounts under the currency's RoundingPolicy, distributing any remainder so that the parts always sum to this value rounded to the policy.

    Declaration
    public ImmutableArray<MonetaryValue> Allocate(params ReadOnlySpan<decimal> ratios)
    Parameters
    Type Name Description
    ReadOnlySpan<decimal> ratios

    The relative weights of each part. Weights can be any non-negative values and do not need to sum to 1 or 100.

    Returns
    Type Description
    ImmutableArray<MonetaryValue>
    Remarks

    The value is first rounded to the policy using ToEven rounding, and the parts always sum exactly to that rounded value. The remainder that results from rounding the individual parts down to the policy's smallest unit is distributed one unit at a time to the parts that lost the largest fraction (the "largest remainder" method), with ties resolved in favor of earlier parts. For equal allocations this means earlier parts receive the extra units, i.e. USD 100.00 allocated into 3 parts yields 34.34, 33.33 and 33.33.

    Negative values are allocated the same way as their absolute value with the parts negated. Parts with a zero ratio are always zero. A default value is allocated into default values.

    Exceptions
    Type Condition
    ArgumentException

    ratios is empty, contains a negative value, or all values are zero.

    Allocate(int, RoundingPolicy)

    Allocates this value into the specified number of equal parts that are valid amounts under the specified rounding policy, distributing any remainder so that the parts always sum to this value rounded to the policy.

    Declaration
    public ImmutableArray<MonetaryValue> Allocate(int count, RoundingPolicy policy)
    Parameters
    Type Name Description
    int count

    The number of parts to allocate the value into.

    RoundingPolicy policy

    The rounding policy that determines the smallest unit that parts are allocated in, i.e. a policy with 0 decimal digits allocates in whole units of the currency.

    Returns
    Type Description
    ImmutableArray<MonetaryValue>
    Remarks

    The value is first rounded to the policy using ToEven rounding, and the parts always sum exactly to that rounded value. The remainder that results from rounding the individual parts down to the policy's smallest unit is distributed one unit at a time to the parts that lost the largest fraction (the "largest remainder" method), with ties resolved in favor of earlier parts. For equal allocations this means earlier parts receive the extra units, i.e. USD 100.00 allocated into 3 parts yields 34.34, 33.33 and 33.33.

    Negative values are allocated the same way as their absolute value with the parts negated. Parts with a zero ratio are always zero. A default value is allocated into default values.

    Exceptions
    Type Condition
    ArgumentOutOfRangeException

    count is less than 1.

    Allocate(ReadOnlySpan<decimal>, RoundingPolicy)

    Allocates this value into parts proportional to the specified ratios that are valid amounts under the specified rounding policy, distributing any remainder so that the parts always sum to this value rounded to the policy.

    Declaration
    public ImmutableArray<MonetaryValue> Allocate(ReadOnlySpan<decimal> ratios, RoundingPolicy policy)
    Parameters
    Type Name Description
    ReadOnlySpan<decimal> ratios

    The relative weights of each part. Weights can be any non-negative values and do not need to sum to 1 or 100.

    RoundingPolicy policy

    The rounding policy that determines the smallest unit that parts are allocated in, i.e. a policy with 0 decimal digits allocates in whole units of the currency.

    Returns
    Type Description
    ImmutableArray<MonetaryValue>
    Remarks

    The value is first rounded to the policy using ToEven rounding, and the parts always sum exactly to that rounded value. The remainder that results from rounding the individual parts down to the policy's smallest unit is distributed one unit at a time to the parts that lost the largest fraction (the "largest remainder" method), with ties resolved in favor of earlier parts. For equal allocations this means earlier parts receive the extra units, i.e. USD 100.00 allocated into 3 parts yields 34.34, 33.33 and 33.33.

    Negative values are allocated the same way as their absolute value with the parts negated. Parts with a zero ratio are always zero. A default value is allocated into default values.

    Exceptions
    Type Condition
    ArgumentException

    ratios is empty, contains a negative value, or all values are zero.

    © Singulink. All rights reserved.