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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conversion to dozens 1

Status
Not open for further replies.

newfrontiers

Programmer
Oct 17, 2001
134
US
Hopefully someone may shed light on how to convert a quantity into dozens and pieces.

For example, if the quantity is 25 I would like the system to show 2 dozens and 1 piece. Or if the quantity is 1 piece I would like the system to show 1 piece. Right now I have the system dividing the quantity by 12, so 1 piece shows as 0.833333333.

Thanks for the help.
 
Here you go:
Function CDozens(iValue As Integer) As String
Dim dzn As Integer
Dim pcs As Integer
dzn = Int(iValue / 12)
pcs = iValue - dzn * 12
CDozens = dzn & "." & pcs
End Function


HTH

Ben ----------------------------------------
Ben O'Hara
Home: bpo@SickOfSpam.RobotParade.co.uk
Work: bo104@SickOfSpam.westyorkshire.pnn.police.uk
(in case you've not worked it out get rid of Sick Of Spam to mail me!)
Web: ----------------------------------------
 
Off the top of my head you could use something like the following...

dozens = amount \ 12 ' notice the "\"...returns only integer part

pieces = amount - ( 12 * dozens ) ' this will give you the rest

so...

dozens: 25 \ 12 = 2
pieces: 25 - ( 12 * 2 ) = 1 If we knew what it was we were doing, it would not be called research, would it? - Albert Einstein [atom]

Robert L. Johnson III, A+, Network+, MCP
Access Developer/Programmer
robert.l.johnson.iii@citigroup.com
 
Not so sure about the grammar but the arith. here is good.

Re grammer, I understand Dozen to proper syntax for singular and plural, so dozens would not be correct (except in the generic sense of an undefined quantity of more than 1 dozen and in quantities which are even multiples of 12). Also, it is not common to list 0 quantities, as in 2 Dozen and 0 pieces, or the reverse -0 dozen and 3 pieces, so some additional work should be applied to the return string.

Finally, if the requirement is to list quantity groups, the process should (?) go to the additional level(s) of dozens (12 dozen = 144 = some name i can't rember at the moment perhaps "Gross"?

Then, perhaps the whole issue should be considered differently. If there is a need to categorize quantities, Should the quantity type be included in the calling args, and then break the qty arg down by the type? So qtyType "Liquid Measure", should return Gallons, Quarts, Pints and ounces? and so on and so forth?




Code:
Public Function basNum2Dzn(QtyIn As Long) As String

    'Michael Red    9/7/2002    Tek-Tips thread705-353436

    Dim Pcs As Integer
    Dim Dzns As Long

    Pcs = QtyIn Mod 12
    Dzns = (QtyIn - Pcs) / 12

    basNum2Dzn = Dzns & " Dozen and " & Pcs & " Pieces"

End Function
MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top