Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ounces and pounds conversion

Status
Not open for further replies.

spyderco

Programmer
Jan 23, 2005
107
US
I have a $num that contains ounces. I need to convert these ounces into pounds and keep the extra ounces. I cannot divide the number by 16 because that gives a decimal, I need the real left over ounces, too.

I need them separated into two variables $ounces and $pounds. Any ideas?
 
You still need to divide the number by 16, give this a shot:
Code:
my $ounces = 25;
my $pounds = int($ounces / 16);
my $remaining = $ounces - ($pounds * 16);

print "$ounces oz is $pounds lbs and $remaining oz.\n";
 
or:

Code:
my $ounces = 37;
print "$ounces oz is @{[int($ounces / 16)]} pounds and @{[$ounces % 16]} ounces\n";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top