Re: Variable division, assignment and sprintf in one line
- From: Jenda@xxxxxxxxxxx (Jenda Krynicky)
- Date: Thu, 29 Nov 2007 01:26:55 +0100
From: Steve Bertrand <iaccounts@xxxxxxxxxx>
Hi again all,
Is there a way that one can use sprintf on a variable and assign the
value back to the variable without having the leading $var= ?
$var = sprintf ("%.2f", (($var /=1024) /=1024)))
What the ...?!?
/= ?
You divide the value of $var by 1024, assign it back to $var, divide
it by another 1024, assign it again to $var, then format the
resulting number using sprinf() and assign it to $var?!? Why???
$var = sprintf ("%.2f", (($var / 1024) / 1024));
will do the same as will
$var = sprintf ("%.2f", $var / (1024*1024));
And it will be more efficient because the multiplication will be done
at compile time (once) and you'll only do a single division each
time. Which is also more precise, though in this case it doesn't seem
to matter.
Jenda
===== Jenda@xxxxxxxxxxx === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
.
- Follow-Ups:
- Re: Variable division, assignment and sprintf in one line
- From: Steve Bertrand
- Re: Variable division, assignment and sprintf in one line
- From: Steve Bertrand
- Re: Variable division, assignment and sprintf in one line
- References:
- Variable division, assignment and sprintf in one line
- From: Steve Bertrand
- Variable division, assignment and sprintf in one line
- Prev by Date: extracting fields from a matching line
- Next by Date: Perl upgrade @INC help
- Previous by thread: Re: Variable division, assignment and sprintf in one line
- Next by thread: Re: Variable division, assignment and sprintf in one line
- Index(es):
Relevant Pages
|