-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of
Tom Phoenix
Sent: Saturday, July 15, 2006 3:22 PM
To: Ralph H. Stoos Jr.
Cc: beginners perl
Subject: Re: Help with Stupid question

>> On 7/15/06, Ralph H. Stoos Jr. <[EMAIL PROTECTED]> wrote:
>>
>> I want to know if / how the $buf/25400 part can
>> be formatted to be a number with only two or three decimal places.

> In Perl, that kind of formatting is generally done with printf or its
> related function sprintf. Where sprintf is a function which returns a
> formatted string, printf goes a step further and prints the string.
> They're documented in perlfunc, but this example may be all you need:
>
>   my $result = sprintf "%.3f", $buf/25400;
>


Just one caveat here: as I understand it, sprintf() will not round the
decimal, it will just truncate it, so if you need to round up or down
the number, I would suggest looking through the math modules.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to