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 |
|
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 |
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 |
|
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 |
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 |
|
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 |
| RoundingPolicy | policy | The rounding policy that determines the smallest unit that parts are allocated in, i.e. a policy with |
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 |
|