[ic] [PATCH] Expand range of round_to_frac_digits to handle exponentized numbers
Mike Heins
mike at perusion.com
Wed Sep 2 16:38:38 UTC 2009
Quoting Brian J. Miller (wiggins at danconia.org):
> Mike Heins wrote:
> > Quoting Brian J. Miller (brian at endpoint.com):
> >> ---
> >> lib/Vend/Util.pm | 20 +++++++++++++++-----
> >> 1 files changed, 15 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/lib/Vend/Util.pm b/lib/Vend/Util.pm
> >> index 8356b84..5be6b5a 100644
> >> --- a/lib/Vend/Util.pm
> >> +++ b/lib/Vend/Util.pm
> >> @@ -269,12 +269,22 @@ sub round_to_frac_digits {
> >> else {
> >> $digits = 2;
> >> }
> >> - my @frac;
> >> - $num =~ /^(-?)(\d*)(?:\.(\d+))?$/
> >> - or return $num;
> >> + if ($num =~ /^(-?)(\d*)(?:\.(\d+)(?:e-(\d+)))?$/) {
> >> + # this number sufficiently close to zero for our purposes
> >> + return 0;
> >> + }
> >
> > Don't we want to return 0.00 (or whatever the frac_digits are? What if it is -1?
> >
>
> I guess it depends on the context used (aka numeric vs. string), but yes
> I'd be fine with that. Do you mean if $frac_digits is -1? I'm not clear
> exactly the use case for the subroutine, hence my e-mail here. Carl
> Bailey also suggested that if $frac_digits is 0 there is currently a
> trailing "." included which might need to be removed.
>
> If you can provide more clarity above I'm happy to whip something up.
I am not trying to deal with negative digits of precision. 8-\
You have it right now as "return 0" if the number is a small negative
exponent. That means you are not going to conform to "round to frac
digits", which would mean in the standard US locale 0.00.
--
Mike Heins
Perusion -- Expert Interchange Consulting http://www.perusion.com/
phone +1.765.328.4479 <mike at perusion.com>
"Laughter is inner jogging." -- Norman Cousins
More information about the interchange-users
mailing list