, or 10 quintillion. While insufficient to count the carbon atoms in a 60-carat diamond (that being Avogadro's number, over
), TDoubleLong values can represent long time periods (over 3 billion seconds per century), or money amounts in accounting applications, where rounding is subject to legal, not just mathematical, constraints.
Here is a program fragment to compute 7% of a monetary amount, rounding in three application-specific ways. It works for any unit of currency; tenths of a cent, or mills, are often used:
Note how TDoubleLong balance = ComputeCurrentAccountBalance();
TDoubleLong sevenPercentOfBalance = (balance * 7) / 100;
TDoubleLong remainder = (balance * 7) % 100; // 0 <= remainder < 100
switch (roundingType) {
kCurrencyTruncate: // integer arithmetic truncates by default
break;
kCurrencyRoundUp:
if (remainder > 0)
sevenPercentOfBalance += 1;
break;
kCurrencyAddHalfAndTruncate:
if (remainder >= 50)
sevenPercentOfBalance += 1;
}
int and TDoubleLong operands are mixed in operations.