473,387 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Convert ounces to pounds and ounces

I have an invoice that lists the various products' weights in ounces. My client would then like to total those amounts (no big deal), but then post the total amount in the format of "X Lbs and Y Oz".
Can anyone come up with a means of deriving such text items? By the way, he would like to reflect the ounces to the first decimal point (each of the items carries their weight to a single digit).
Thanks for the assistance.
Sep 23 '10 #1

✓ answered by OldBirdman

I know there are 16 Avoirdupois ounces in a pound, 12 Troy ounces.
A condition here is "By the way, he would like to reflect the ounces to the first decimal point (each of the items carries their weight to a single digit)." So we have partial ounces.
Expand|Select|Wrap|Line Numbers
  1. oz = 42.7
  2. lb = Int(oz / 16)  'Use 12 if Troy ounces
  3. oz = oz - (lb * 16) 'Mod Function returns an integer     'Use 12 if Troy ounces
  4. answer = lb & " Lbs and " & Format(oz,"0.0") & " Oz"  'To ALWAYS show Oz to 1 decimal place, even if whole number
  5. '2 Lbs and 10.7 Oz

4 7438
Mariostg
332 100+
Knowing there are 16 ounces in a pound:
Expand|Select|Wrap|Line Numbers
  1. oz = 8
  2. lb = Int(oz / 16)
  3. oz = oz Mod 16
  4. answer = lb & " lbs and " & oz & " ounces"
  5.  
Sample above returns answer = 0 lbs and 8 ounces
Sep 24 '10 #2
OldBirdman
675 512MB
I know there are 16 Avoirdupois ounces in a pound, 12 Troy ounces.
A condition here is "By the way, he would like to reflect the ounces to the first decimal point (each of the items carries their weight to a single digit)." So we have partial ounces.
Expand|Select|Wrap|Line Numbers
  1. oz = 42.7
  2. lb = Int(oz / 16)  'Use 12 if Troy ounces
  3. oz = oz - (lb * 16) 'Mod Function returns an integer     'Use 12 if Troy ounces
  4. answer = lb & " Lbs and " & Format(oz,"0.0") & " Oz"  'To ALWAYS show Oz to 1 decimal place, even if whole number
  5. '2 Lbs and 10.7 Oz
Sep 24 '10 #3
Mariostg
332 100+
OldBirdMan, you are eagle eye but I am sure so does the OP.
Sep 24 '10 #4
That was a great solution!! For others reading this thread, I placed the three lines of code (shown as 2,3,and 4) into a query where I had the total ounces to be converted. It works perfectly.
Thanks again!!
Sep 24 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Robert Zierhofer | last post by:
hi there, it seems as if i can´t convert the euro and pound sign to their html equivalents. i tried eregi_replace("€", "€", $haystack); eregi_replace("£", "£", $haystack); as...
19
by: Lauren Quantrell | last post by:
I have a stored procedure using Convert where the exact same Convert string works in the SELECT portion of the procedure but fails in the WHERE portion. The entire SP is listed below....
2
by: Calvin | last post by:
Hi, I'm developing an eCommerce site and need to change the currency displayed from Dollars to Pounds. SqlServer field is set to Money. Then on Product List page, following code is used......
1
by: Logan X via .NET 247 | last post by:
It's official....Convert blows. I ran a number of tests converting a double to an integer usingboth Convert & CType. I *ASSUMED* that CType would piggy-back ontop of Convert, and that performance...
2
by: Joel Moore | last post by:
Maybe I'm just easily baffled after an all-nighter but I can't seem to figure out how to represent a BitArray as a hexadecimal string. For example: Dim outputBank As New BitArray(8) ...
4
by: Eric Lilja | last post by:
Hello, I've made a templated class Option (a child of the abstract base class OptionBase) that stores an option name (in the form someoption=) and the value belonging to that option. The value is...
5
by: Cally | last post by:
Hello, I would like to convert a field from ntext field found in one database table to float field found in another database table. The reason why I want to do this is a long one. I have...
7
by: whatluo | last post by:
Hi, all I'm now working on a program which will convert dec number to hex and oct and bin respectively, I've checked the clc but with no luck, so can anybody give me a hit how to make this done...
3
by: Convert TextBox.Text to Int32 Problem | last post by:
Need a little help here. I saw some related posts, so here goes... I have some textboxes which are designed for the user to enter a integer value. In "old school C" we just used the atoi function...
1
by: johnlim20088 | last post by:
Hi, Currently I have 6 web projects located in Visual Source Safe 6.0, as usual, everytime I will open solution file located in my local computer, connected to source safe, then check out/check in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.