Specifics of orders and charges amounts calculation and rounding when a discount is applied

General

The amount of the order and the amounts of the charges are rounded off to two decimal places. When a discount is applied, this may lead to a discrepancy between the amount of the order and the amounts of the charges for the subscription. To avoid this, rounding off and applying of a discount to the amounts of the order and charges is performed according to a special algorithm. Corrections are applied to the amounts of charges and to the amount of discounts on charges.

Stages of order amount calculation and rounding

The total amount of an order is calculated in several stages:

  1. Calculation of the order amount without the discount applying.
  2. Rounding off of the order amount to two decimal places according to the mathematical rounding rule.
  3. Calculation of the discount amount from the rounded off amount of the order. The discount amount is calculated as the product of the discount in unit fractions by the rounded off amount of the order that was calculated at the stage 2.
  4. Calculation of the order amount with the discount applied. The order amount with the discount is calculated as the difference between the rounded off amount of the order that was calculated at the stage 2 and the discount amount from the rounded off amount of the order that was calculated at the stage 3.
  5. Calculation of the standard order amount with the discount applied: the order amount with the discount applied that was calculated at the stage 4 is rounded off to two decimal places according to the mathematical rounding rule.
  6. Calculation of the standard order discount: it is calculated as the difference between the rounded off amount of the order that was calculated at the stage 2 and the standard order amount with the discount applied that was calculated at the stage 5.

An example of the order standard amount and the Order standard discount calculation and rounding off

Initial conditions:

Order attributeValue
TypeSales order
Subscription period3 months
Created at17.06.2018
Setup fee for the plan period$0,00
Recurring fee for the plan period, per month$0,00
Setup fee for the resource unit$0,00
Recurring fee for the resource unit, per month$8,00

Ordered amount of the resource

7
Applicable discount34,3%

Calculation:

  1. Multiply the subscription period by the amount of the resource, and by the Recurring fee for the resource unit, per month. As a result, you receive the unrounded order amount without the discount applying, which is equal to $168,00.
  2. Round off the product to two decimal places. As a result, you receive the rounded off order amount without the discount applying, which is equal to $168,00.
  3. Multiply the rounded off order amount without the discount applying by the discount in unit fractions. As a result, you receive the discount amount from the rounded off amount of the order, which is equal to $57,624.
  4. Subtract the discount amount, which was found at the previous step, from the rounded off order amount without the discount applying, which was found at the step 2. As a result, you receive the order amount with the discount applied, which is equal to $110,376.
  5. Round off the difference to two decimal places. As a result, you receive the rounded off order amount with the discount applied, which is equal to $110,38. This value is the standard order amount, to which you should later bring the sum of charges standard amounts.
  6. Subtract the standard order amount, which was found at the previous step, from the rounded off order amount without the discount applying, which was found at the step 2. As a result, you receive the standard order discount, which is equal to $57,62. You should later bring the sum of charges standard discounts to that value using the corrections.


Stages of charges amounts calculation and rounding

Calculation and rounding off of the amounts and discounts of every type of charges is carried out according to the same algorithm as the calculation and rounding off of the order amount and discount.

In case when the charge amount should be rounded off to zero according to the mathematical rule, its value is set as 0,01 instead during the calculation and rounding off.

The only exception is when the 100% discount is applied. In that case, the charge discount value is set as 0,01, and the charge amount is set as zero.

Example of the calculation and rounding off of the charges amounts and discounts

Initial conditions:

A subscription with a billing day on the first day of month generated four charges with the attributes given in the table below.

The period of charge should be always rounded off to three decimal places.


Charge attributeAttribute value of the charge 1Attribute value of the charge 2Attribute value of the charge 3Attribute value of the charge 4
TypeRecurring fee charge for the resourceRecurring fee charge for the resourceRecurring fee charge for the resourceRecurring fee charge for the resource
Charge period, in month0,467 month1 month1 month0,533 month
Recurring fee for the resource unit, per month$8,00

Ordered amount of the resource

7
Applicable discount34,3%

Calculation:

  1. For each charge multiply the charge period by the amount of the resource, and by the Recurring fee for the resource unit, per month. As a result, you receive:
    1. The unrounded amount of the charge 1 without the discount applying, which is equal to $26,152.
    2. The unrounded amount of the charge 2 without the discount applying, which is equal to $56,000.
    3. The unrounded amount of the charge 3 without the discount applying, which is equal to $56,000.
    4. The unrounded amount of the charge 4 without the discount applying, which is equal to $29,848.
  2. Round off the products to two decimal places. As a result, you receive:
    1. The rounded off amount of the charge 1 without the discount applying, which is equal to $26,15.
    2. The rounded off amount of the charge 2 without the discount applying, which is equal to $56,00.
    3. The rounded off amount of the charge 3 without the discount applying, which is equal to $56,00.
    4. The rounded off amount of the charge 4 without the discount applying, which is equal to $29,85.
  3. For each charge multiply the rounded off charge amount without the discount applying by the discount in unit fractions. As a result, you receive:
    1. The discount amount from the rounded off amount of the charge 1, which is equal to $8,96945.
    2. The discount amount from the rounded off amount of the charge 2, which is equal to $19,20800.
    3. The discount amount from the rounded off amount of the charge 3, which is equal to $19,20800.
    4. The discount amount from the rounded off amount of the charge 4, which is equal to $10,23855.
  4. For each charge subtract the discount amount, which was found at the previous step, from the rounded off the charge amount without the discount applying, which was found at the step 2. As a result, you receive:
    1. The amount of the charge 1 with the discount applied, which is equal to $17,18055.
    2. The amount of the charge 2 with the discount applied, which is equal to $36,79200.
    3. The amount of the charge 3 with the discount applied, which is equal to $36,79200.
    4. The amount of the charge 4 with the discount applied, which is equal to $19,61145.
  5. Round off the results to two decimal places. You receive:
    1. The rounded off amount of the charge 1 with the discount applied, which is equal to $17,18.
    2. The rounded off amount of the charge 2 with the discount applied, which is equal to $36,79.
    3. The rounded off amount of the charge 3 with the discount applied, which is equal to $36,79.
    4. The rounded off amount of the charge 4 with the discount applied, which is equal to $19,61.
    These values are the standard amounts of charges, to which you should later apply correction in order to bring the sum of standard charges amounts to the standard amount of order.
  6. For each charge subtract the standard charge amount, which was found at the previous step, from the rounded off charge amount without the discount applying, which was found at the step 2. As a result, you receive:
    1. The standard discount for the charge 1, which is equal to $8,97.
    2. The standard discount for the charge 2, which is equal to $19,21.
    3. The standard discount for the charge 3, which is equal to $19,21.
    4. The standard discount for the charge 4, which is equal to $10,24.
    You should later apply correction to the standard charges discounts to bring their sum to the standard discount for the order.


Calculation of corrections amounts

Two types of corrections are used:

  • Correction of standard charges amounts.
  • Correction of standard charges discounts.

To calculate the correction of standard charges amounts:

  1. Sum up the standard charges amounts.
  2. Subtract the received sum from the standard order amount.

To calculate the correction of standard charges discounts:

  1. Sum up the standard charges discounts.
  2. Subtract the received sum from the standard order discount.

Example of the corrections calculation

Calculate the correction of standard charges amounts:

  1. Sum up the standard charges amounts: $17,18 + $36,79 + $36,79 + $19,61 = $110,37.
  2. Subtract the received sum from the standard order amount: $110,38 — $110,37 = $0,01.

Calculate the correction of standard charges discounts:

  1. Sum up the standard charges discounts: $8,97 + $19,21 + $19,21 + $10,24 = $57,63.
  2. Subtract the received sum from the standard order discount: $57,62 — $57,63 = -$0,01.

Application of corrections

Correction of standard charges amounts

Corrections are applied only to the Recurring fee charges amounts.

Corrections of standard charges amounts are applied according to following algorithm:

  1. The periods of the first charge and of the last charge are compared. If the periods are equal, the last charge is selected. If they are not, then the charge with the longer period is selected. 

    If the correction is applied for the change or switch plan orders, then the last charge is compared to the charge for the current billing period instead of the first one.

  2. The amount of selected charge is recalculated: the correction amount is added to the standard charge amount. If the result is a negative value, the charge amount is set as zero, and the received negative value is added to the amount of the next charge, which is selected according to principles given at the step 1. This operation is carried out until the result is non-negative value.

Example of the Charges amounts recalculation using correction

The standard order amount is $0,19.

A subscription generated six charges with the following periods and standard amounts:

  • Charge 1 with a period of 0,4 month and an amount of $0,02.
  • Charge 2 with a period of 1 month and an amount of $0,05.
  • Charge 3 with a period of 1 month and an amount of $0,05.
  • Charge 4 with a period of 1 month and an amount of $0,05.
  • Charge 5 with a period of 1 month and an amount of $0,05.
  • Charge 6 with a period of 0,6 month and an amount of $0,03.

Therefore the correction is equal to: $0,19 — ($0,02 + $0,05 + $0,05 + $0,05 + $0,05 + $0,03) = — $0,06.

Applying correction:

  1. Compare periods of charge 1 and of charge 6: 0,4 < 0,6. charge 6 period is longer.
  2. Apply correction to the amount of the charge 6: $0,03 + (- $0,06) = — $0,03. The result is a negative value.
  3. Set the amount of the charge 6 to zero.
  4. To apply the rest of the correction, compare periods of charge 1 and of charge 5: 0,4 < 1 . charge 5 period is longer.
  5. Apply the rest of the correction to the amount of the charge 5: $0,05 + (- $0,03) = $0,02. The result is a positive value. Correction application is finished.

As a result, you've received the following charges:

  • Charge 1 with an amount of $0,02.
  • Charge 2 with an amount of $0,05.
  • Charge 3 with an amount of $0,05.
  • Charge 4 with an amount of $0,05.
  • Charge 5 with an amount of $0,02.
  • Charge 6 with an amount of $0,00.

The sum of charges amounts after the correction application is: $0,02 + $0,05 + $0,05 + $0,05 + $0,02 + $0,00 = $0,19, which is equal to the standard order amount.

Correction of standard charges discounts

Corrections are applied only to the Recurring fee charges discounts.

Corrections of standard charges discounts are applied according to following algorithm:

  1. The periods of the first charge and of the last charge are compared. If the periods are equal, the last charge is selected. If they are not, then the charge with the longer period is selected.

    If the correction is applied for the change or switch plan orders, then the last charge is compared to the charge for the current billing period instead of the first one.

  2. The discount for the selected charge is recalculated: the correction amount is added to the standard charge discount. If the result is a negative value, the charge discount is set as zero, and the received negative value is added to the discount for the next charge, which is selected according to principles given at the step 1. This operation is carried out until the result is non-negative value.

Example of the charges discounts recalculation using correction

The standard order discount is $0,81.

A subscription generated six charges with the following periods and standard discounts:

  • Charge 1 with a period of 0,667 month and a discount of $0,10.
  • Charge 2 with a period of 1 month and a discount of $0,15.
  • Charge 3 with a period of 1 month and a discount of $0,15.
  • Charge 4 with a period of 1 month and a discount of $0,15.
  • Charge 5 with a period of 1 month and a discount of $0,15.
  • Charge 6 with a period of 0,333 month and a discount of $0,05.

Therefore the correction is equal to: $0,81 — ($0,10 + $0,15 + $0,15 + $0,15 + $0,15 + $0,05) = $0,06.

Applying correction:

  1. Compare periods of charge 1 and of charge 6: 0,667 > 0,333. charge 1 period is longer.
  2. Apply correction to the discount for the charge 1: $0,10 + $0,06 = $0,16. The result is a positive value. Correction application is finished.

As a result, you've received the following charges:

  • Charge 1 with a discount of $0,16.
  • Charge 2 with a discount of $0,15.
  • Charge 3 with a discount of $0,15.
  • Charge 4 with a discount of $0,15.
  • Charge 5 with a discount of $0,15.
  • Charge 6 with a discount of $0,05.

The sum of charges discounts after the correction application is: $0,16 + $0,15 + $0,15 + $0,15 + $0,15 + $0,05 = $0,81, which is equal to the standard order discount.