note
mojotoad
Ah. My favorite here is the <code>snap_units()</code> function. There was a time when I was playing around with rounding fractions of stock shares -- to the nearest 1/8 or 1/16 value -- before the exchanges I was focused upon switched to arbitrary decimal representations of stock shares.
<p>
In the CB, [tye] suggested the following change in <code>snap_units()</code> to avoid potential rounding errors:
<p>
from:
<p>
<code>
my $factor = 1/$units;
</code>
to:
<code>
my $factor = int( 1/$units + 0.5 );
</code>
<p>
The drawback is that for fractional cases, $units must be 1/N, where N is an integer. I'm not super clear on the potential rounding errors; nor am I clear on the potential utility of arbitrary $units. Perhaps [tye|certain people] can elucidate for our edification.
<p>
Matt
<p>
P.S. For some prior discussion of this stuff, check out [id://222013].
222205
222205