Number formatting

From: Colin Johnstone (Colin.Johnstone_at_westfield.com.au)
Date: 08/05/04


To: beginners@perl.org
Date: Thu, 5 Aug 2004 12:02:34 +1000

Hi all,

I am doing conversions from square metres to square feet for example.

I have a regex that removes any commas or spaces in a number.

I then do the conversion

return an integer

but then want to display the number with the commas or spaces put back in
to make it easier to read.

What do you suggest?

                my $units = iwpt_dcr_value('dcr.lettableArea.units');
                my $area = iwpt_dcr_value('dcr.lettableArea.Area');
 
                $modifiedArea =~ s/,\s//;
 
                $squareMetres = ( $units eq 'square metres' ) ? $area :
int $modifiedArea * 0.0929;
                $squareFeet = ( $units eq 'square feet' ) ? $area
: int $modifiedArea * 10.764;
 
                $lettableArea = $squareMetres .qq[m<sup>2</sup> or ] .
$squareFeet . qq[f<sup>2</sup> (approx)];
 
                iwpt_output( $lettableArea );

Regards

Colin



Relevant Pages

  • Re: Number formatting
    ... > I am doing conversions from square metres to square feet for example. ... > I have a regex that removes any commas or spaces in a number. ...
    (perl.beginners)
  • Re: SIDI boots
    ... to make conversions off the top of their heads. ... round hectares at all, but I can easily understand and visualise ... square metres and square kilometres? ...
    (uk.rec.motorcycles)