I need to store an arbitrary length decimal in c++. The following is the structure we are considering:
<NumberAsString(char*), DecimalAt(int32)>
An example of this would be:
1.00003940400
<"100003940400", 11>
0.0004
<"0004", 4>
10
<"10", 0>
Does this seem like a good way to store a decimal? Is there a better way to do this?
Another possible approach would be similar to how the "money modules" often work in javascript, for example, giving the number as an int "in cents" -- $102.25 being stored as 10225. And we'd store it like this:
<int64, int64> # the second int64 would be the decimal places
For example, if we allow "5 decimal places of precision", then we would store:
12.250
<12, .250E5> // or <12, 25000>
Which approach would be better -- or perhaps use something else entirely?