Basically it is required to support very large numbers and a very large number of decimal places. There is quite some debate on how this can be realized efficiently. Candidates identified are
longs (pounds & fraction)
Decimalclass (probably wrapping two longs)
doubleshould be ruled out as inaccurate
Numbershould be ruled out as being abstract and non-precise
We have decided on using a Decimal class, that will encapsulate 2 longs - one long for the integer part and the other for the fractional part. Arithmetic needs to take this into account.
doubleshould be ruled out as inaccurate *
Numbershould be ruled out as being abstract and non-precise We have decided on using a Decimal class, that will encapsulate 2 longs - one long for the integer part and the other for the fractional part. Arithmetic needs to take this into account. ==Additional Notes ===Possible Issue 1000/3 = 333.33, but 333.33*3 = 999.99 which is one penny short. Since this would not work in an accounting application, need to consider an api where the penny is accounted for, Several options: * return an array where the first element is the quotient, and the second element is the excpetion: [333.33, 333.34] * Or represent the result and remainder [333.33, .01] Both of these approaches would require a third number to represent the remainder or exception. In both approaches, the remainder or exception needs to be included in further calculations. So 100/3 = [33, 34]. Now let's say we want to divide that by 4, so the 33 term produces [8,9] and the 34 term produces [8,10], so how do you capture all of those remainders? Another issue. To show it clearly, assume 0 decimal precision, so - 34/4 = [8, 10] using exception approach, or [8, 2] using remainder approach. In either case, "multiplying" back yields the correct result: 8+8+8+10 = 34. But shouldn't that be better represented as 8+8+9+9? so how do you represent that. Another approach - retain the fractional representation and work with the formatter to iterate through the results, adding the missing penny to the last one. Then all arithmetic would be fractional arithmetic.