Balance and Meter Precision

Balances and meters have precision values that determine how quantities are handled before they are applied to the balance or meter.

Precision determines the number of digits to the right of the decimal point that are used to express balance or meter value. It is the position at which fractional rating results are rounded. To determine rounding, the original number is truncated to one digit more than the number of digits in the precision and then that digit determines how to adjust the digits within the precision to the nearest number; if the number is between 0 and 4, the value is rounded down, and if the number is between 5 and 9, the value is rounded up.
Note: A negative number rounded up is rounded away from zero, and a negative number rounded down is rounded towards zero.

The rounding direction is used in conjunction with the precision value to determine the update amount when rates are applied. If the digit in the position to the right of the precision amount is 5 or greater, the digits within the precision are rounded up. For example, if a charge calculation is 1.995 and the precision is 2, the third digit to the right of the decimal place is examined. Because it is a 5, the digits included in the specified precision (.99) are rounded up, resulting in 2.00. If a charge calculation is 1.994, the digits are rounded down to 1.99. Rounding is always done to the nearest value at the specified precision. The maximum precision for balances and meters is 7.

Balance precision specifies the rounding applied to balance updates for each transaction. Intermediate results during rating are not rounded, but the final result is. The stored balance or meter is therefore rounded to this precision. If there are multiple events within a transaction, for example, with multiple service contexts, or with a recurring event during usage rating, the balance updates for each individual event are rounded to this precision.

Important: Balance precision and rounding are unrelated to conversions that occur between the rating formula unit and the event unit. Internally, the MATRIXX Charging Application uses a unit conversion precision of 12 decimal places. For example, if a rate charges $0.03 per minute, the rating formula unit is $0.03. If the event unit is seconds, the coefficient is converted to $0.0005 per second (0.03 ÷ 60) to yield much greater accuracy. This is only required when the rating formula has a quantity unit that differs from the event unit. In such cases, the coefficient is converted to the event unit before rating occurs.

The conversion of the rating formula amount per unit makes the precision as fine or as coarse as the event unit. When the event unit is smaller than the rating formula unit, the rating formula amount is divided so that it represents the smaller unit. If the event unit is larger than the rating formula unit, the rating formula amount is multiplied. After the conversion is complete, the event quantity is applied to the converted rating formula and the total amount is then adjusted for the precision and rounding values configured for the balance or meter. For example, if an event is measured in one-second increments and a rating formula is $0.03 per minute, the rating formula is converted to $0.0005 per second. If the call lasts 11 seconds, the total charge to the balance is $0.0055. The amount is then rounded up to $0.01, which is what will be charged to the balance, even though the duration of the event was less than the rating formula quantity unit.

Another area of precision occurs when calculating beat amounts and balance amounts. The balance unit and beat unit are reliant and if they are much different in size, and result in formulas that contain a lot of significant digits, there is less precision during calculations. This causes unexpected rating results. For example, say a balance is measured in MB and uses a beat of 1 KB. Precise conversion from KB to MB requires up to 10 fractional digits. However, as noted, the maximum precision for balances and meters is 7; this makes it impossible to charge exactly 1 KB to a MB balance. For example:

  • 1 KB = 1024 bytes = 0.0009765625 MB, which rounds up to 0.0009767 MB, or 1024.1441792 bytes (overcharge).
  • 2 KB = 2048 bytes = 0.0019531250 MB, which rounds down to 0.0019530 MB, or 2047.868928 bytes (undercharge).

To avoid inaccuracies as much as possible, MATRIXX support recommends pricing to use the same unit for beats and balances when reasonable, ideally with zero decimal places of precision so that conversions occur with integer quantities. In addition, try to use formulas that result in fewer significant digits. Integers are best because they tend to require less digits and have less fractional digits. For example:

  • 1 MB = 1048576 bytes
  • 1 GB = 1073741824 bytes
  • 1 byte = 0.000000095367431640625 MB
  • 1 byte = 0.000000000931322574615478515625 GB

In such cases, it is preferable to denominate in bytes rather than GB or MB, because these units often result in rounding errors unless the beat is the same unit.