[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 761
  • Last Modified:

How best to store units of measure (ft & inches, lb & oz, etc.)

I am developing a warehousing program and we need to define the dimensions of the storage locations as well as the weight of the products.  I'm in the initial development phase right now and I am wondering how I should go about storing the units of measure.

We need to have the ability to define specific units of measure, like feet & inches, meters, etc and their relationship to each other (each foot has 12 inches).  Obviously each measurement can have a value and sub value (feet->inches or lb->oz).  Not only do I need to take into account the easiest way to store this data, but the easiest way to retrieve and use the data.

My initial thought was to create two fields.  One for Unit of measure and one for sub unit of measure.  This however limits us to two levels of measure and makes it impossible to have for example kilometers, meters, centimeters, etc.  Then I thought maybe we could store the data in a custom designed format.  Create a class to convert and use the fields as well as retrieve and store them.

What I need to know is what my best option is.  What are the pros and cons to each method.

0
header
Asked:
header
  • 7
  • 4
  • 2
  • +2
1 Solution
 
simonetCommented:

There are 2 approaches to this problem:

1) Store everything in a standard unit, say "inches".

Then, in a separate table, you store the relationship between the standard unit and other units. This other table would look like this:

CodUnit   NameUnit   Multiplier
1          cm          2.54
2          mm          25.4
3          feet        8.333333e-2
...


The multiplier allows you to go from the standard unit to ANY DESIRED unit (1 in = 2.54 cm, 1 in = 25.4 mm, 1 in = 1/12 ft, and so on)


2) Another approach, which makes it easier to store data because you simply store it in whatever unit you already have, is a bit more complicated to code, but it is my favorite approach.

You'll need 2 tables: one to simply store the units, and the other to store the relationship between these units.

Like this:

Table 1 : Units
CodUnit   NameUnit
  1         in
  2         cm
  3         mm
  4         ft
  5         m
... and so on


Table 2 : Multipliers
(is what you need to multiply Unit1 by to get to Unit2)
CodUnit1    CodUnit2    Multiplier
  1            2           2.54
  2            1           0.393700787402
  3            1           25.4
  3            2           0.1
  3            4           3.28083989501e-3
... and so on
   
Then, whenever you have to store the length information to something, all you have to do is to let the user choose what unit he is working with and then store the value of the unit. So, for a 3m tube, he would store:

CodUnit   ValueUnit
  5          3.0

(because 5, in this example, is the code for METER, and 3.0 is the actual length of the tube).

With this, you can easily go from one unit to another using simple SQL queries, and the user doesn't have to worry work his math going from the unit he has to the standard unit all the time.


I have worked on a similar program a while ago, but it was a bit more complex, because it involved several TYPES of units (volume, mass, length), but the 2nd approach above worked fine.

Let me know if you need more help.

Yours,

Alex

0
 
ITugayCommented:
exactly right solution. Have nothing to add.
0
 
kretzschmarCommented:
same for me, nothing to add
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
headerAuthor Commented:
simonet, that was a wonderful explanation.  However I want to clarify the second option.  

What if a box was 2 feet 3 inches?  How would that be entered, stored, and then converted to meters?  What I am wondering about is how to handle 2 UOM's.  Like feet and inches, meters and millimeters, etc.  Would it be best to create a popup entry screen (like the calculators) to enter the value and pass the proper value back to the screen?

Our main measurements will be the Height/Width/Depth of the storage locations as well as the products.  The products will also have a weight associated with them.
0
 
headerAuthor Commented:
simonet, I'm not rejecting your answer because it's wrong, but to allow other experts to comment.

What about using the RegisterConversionType function to register all of our custom UOM's and the conversions between them and then using the Convert function to actually do the conversions.

Has anyone else used this method?
0
 
simonetCommented:
Answering to your previous question:

"2ft 3in" is not a mathematically correct way of expressing any measure. The correct way of expressing such a length would be

2.25 ft

The same goes to 2 1/4ft = 2.25 ft

You don't see anyone expressing 3.5m as "3m 50cm".

Thus mathematically knowing how to express a measure/number will be the minimum requirement for anyone trying to use your application.

Remember that "2ft 3in" is not mathematically correct, althought (go figure!) the Engligh language in the US permits this. However computers do not work with English semantics... mathematics is a much closer way to "talk" to a computer.

Yours,

Alex
0
 
ITugayCommented:
A real sample in addition.

Our documents has different currency and we have to keep original currency and price.
There is database tables:

currency_list
  id_currency,
  cr_name

currency_rate
  fk_currency,
  rate_date,
  rate_value // to national currency

doc_header
  ....
  fk_currency, // document's original currency
  doc_date,
  doc_total, // total summ for specified currency
  doc_int_total // total summ in national currency to allow staistic by easy way

in this case "currency" is the same as "measure" in your case, but a bit complicated, because it changed in time.
As you see it allow to keep original values and allow to make some calculation.
0
 
headerAuthor Commented:
Anyone have an opinion of using RegisterConversionFamily and RegisterConversionType?

I have briefly tested with this and it works great!  I just defined my UOM's as well as their factor to the base and ran a routine at startup to register each UOM.  Then I can use the Convert function to convert from one UOM to another.

simonet, I understand what you are saying and I agree wholeheartedly, but I am now wondering if the RegisterConversionType is the best way of implementing this solution rather than creating my own routines.
0
 
MoondancerCommented:
Greetings.  This question is current, but the other is very old, please do finalize it.  This is what was posted in the other question, and is a second request.

ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if still open in seven days.  Please post closing recommendations before that time.

Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20127001.html
http://www.experts-exchange.com/questions/Q.20288806.html




*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations if this item remains inactive another seven (7) days.  If you are interested in the cleanup effort, please click this link http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed here -> http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @7 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange
0
 
headerAuthor Commented:
I am simply waiting now on an opinion of the RegisterConversionFamily and RegisterConversionType functions and if that is my best way of converting between UOM's?
0
 
simonetCommented:
Header,

for all I know, there's no built-in "conversion" routines in Delphi. Delphi is not a HP-48, thus you cannot simply register your new unit there and you're all set.

Besides, if anyone knew anything about the 2 functions you're talking about, there would probably have been some feedback here about them.

Yours,

Alex
0
 
headerAuthor Commented:
I am saying that it IS that easy.  I was just wondering if someone had previously used these functions.  Check out these functions to learn more:

RegisterConversionFamily
RegisterConversionType
Convert
0
 
MoondancerCommented:
Was this closed prematurely?  Is more needed here to achieve the "A" level grade you assigned?

Thank you,
Moondancer - EE Moderator
0
 
headerAuthor Commented:
No, this was not premature.  simonet answered my question beautifully, that was the reason behind the 'A'.

I just was curious if anybody had used the two functions I mentioned and could offer their opinions.  However, I have been testing them and feel pretty comfortable with them now.
0
 
simonetCommented:
Header,

I found no information on Delphi's Help file about the 2 forementioned functions.

Where did you learn about them? Is it possible they are part of some package you have installed in your machine?

Alex
0
 
headerAuthor Commented:
Well, I do have extra packages, but I first read about it by accident in the Delphi Language Guide that comes with Delphi.  I am using Delphi 6.0 Enterprise.  Those functions are part of the ConvUtils unit and are listed directly in my Help File.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now