[ic] [PATCH] Expand range of round_to_frac_digits to handle exponentized numbers

Mike Heins mike at perusion.com
Wed Sep 2 15:15:09 UTC 2009


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?

> +	elsif ($num =~ /^(-?)(\d*)(?:\.(\d+))?$/) {
> +		# no op
> +	}
> +	else {
> +		warn "Vend::Util::round_to_frac_digits: invalid number ($num)\n";
> +		return $num;
> +	}
> +
>  	my $sign = $1 || '';
> -	my $int = $2;
> -	@frac = split(m{}, ($3 || 0));
> +	my $int  = $2;
> +	my @frac = split(m{}, ($3 || 0));
> +
>  	local($^W) = 0;
>  	my $frac = join "", @frac[0 .. $digits - 1];
>  	if($frac[$digits] > 4) {
> -- 
> 1.5.6.3
> 
> 
> _______________________________________________
> interchange-users mailing list
> interchange-users at icdevgroup.org
> http://www.icdevgroup.org/mailman/listinfo/interchange-users
> 

-- 
Mike Heins
Perusion -- Expert Interchange Consulting    http://www.perusion.com/
phone +1.765.328.4479  <mike at perusion.com>

I don't want to get to the end of my life and find I have just
lived the length of it. I want to have lived the width of it as
well. -- Diane Ackerman



More information about the interchange-users mailing list