# Expected Input Format [Metric]

Ok… first off… I’m an American, and historically Americans know little about day to day use of the Metric system.

I have a need to create a custom textfield that will accept a measurement, that can be in either Metric or Imperial (ft/inches)
The value needs to be checked that it is valid, and then converted to inches (regardless of its input format)

an Imperial value could be entered as 12’3" or 12ft 3 inches
the question is what various formats should I deal with for Metric.
M = meters
mm and cm
would a Metric user ever enter 10M 3cm or would they use 10.3M?

Internally this app will deal in strictly INCHES (and fractions), but convert to/from for input/display purposes

I can’t speak for all Metrics of course, but 10m 3cm seems very weird to me.

Instead of M I would always use m. Also, 10m 3cm is not 10.3 m, but 10.03m. I would expect most people in my country to write it as 10,03 m, (using a comma), but I always use a dot as decimal separator. Fun.

Julen

Just make sure nobody uses the US Survey Inch

Another complication is the varying use of ‘,’ and ‘.’ as separators.
See https://en.wikipedia.org/wiki/Decimal_separator

Yes, both 10m 3cm and 10.03m could be used. Along with 1003 cm

figured I’d get it wrong without looking it up

I am very well versed on the Imperial system

good point

two different opinions I see… so I will error on the side of caution

Nice thing about standards, there are so many to choose from!
To be honest I see the #m #cm most often in EU Commission documents.

I have only seen m and cm in school homework. Usually is only m or only cm, in rare occasion mm, never seen dm.

Example, for height in some countries people usually write 1.75 m while other countries write 175 cm.

As metric guy, I’d say you should accept the value using the higher precision you allow.
If precision is up to cm. then allow to enter it as a whole number. E.g: 103 cm. (equal 1m and 3cm)

But this is up to you and the context. You can even decide to use meter as the base and then allow the enter 1,03 (pay attention the comma is the decimal separator).
The decimal separator is something you also have to consider indeed. You can decide to allow centimeters only to avoid handling decimals.

Then, all ends up to what you are sizing. But I suggest to avoid separate input fields for e.g: meter and cm.

Ok… here is what I came up with… it will accept either Metric and/or Imperial[US] values… you can even mix them
you can also include fractions (1/2, 3/4 etc), although I doubt a metric user would want to do such, but you could
if accepts both world spelling for “meter” (metre)
internally it translates metric units to other values for ease of parsing, the user never sees this

``````Public Function String2Dist(s as string,byref error as boolean) as double
//     Method : String2Dist [String to Distance]
//     Author : R.David S [22Mar2018]
//      Input : a string representing a Metric or Imperial distance measurement
//     Output : a double representing input value as INCHES, error will be true if conversion not possible
// Assumption : app has a boolean value called optionMetric to decide default units
//
Dim unit As String
Dim x As Integer
Dim y As Integer
Dim t As String
Dim v() As String
Dim value As Double
Dim i As Integer
If InStr(s,"|")>0 Or InStr(s,"X")>0 Or InStr(s,"U")>0 Then
error=True
Return 0
End If
//
//t=ReplaceAll(t," ","")
s=Replace(s,"s","") // remove plurals
// metric units [use c=cm  u=mm   x=Meter]
s=Replace(s,"metre","meter") // different spelling
s=Replace(s,"centimeter","c|")
s=Replace(s,"cm","c|")
s=Replace(s,"millimeter","u|")
s=Replace(s,"mm","u|")
s=Replace(s,"meter","X|")
s=Replace(s,"M","X|") // to Separate from mm
// imperial units
s=Replace(s,"feet","'|")
s=Replace(s,"foot","'|")
s=Replace(s,"ft.","|'")
s=Replace(s,"ft","'|")
s=Replace(s,"yard","y|")
s=Replace(s,"yd.","y|")
s=Replace(s,"yd","y|")
s=Replace(s,"inche",ChrB(34)+"|")
s=Replace(s,"inch",ChrB(34)+"|")
s=Replace(s,"in.",ChrB(34)+"|")
s=Replace(s,"in",ChrB(34)+"|")
// c=cm u=mm x=meter  '=foot "=inch
v=Split(s,"|")
For i=0 To v.ubound
s=Trim(v(i))
If s="" Then Continue
unit=Right(s,1)
// no unit provided, so assume based on OptionMetric value
If IsNumeric(unit) Then
unit=ChrB(34) // assume inches as missing unit
If optionMetric Then unit="u" // mm
Else
s=Trim(Left(s,Len(s)-1))
End If
//
// does it contain a "fraction" [3/4]?
//
x=InStr(s,"/")
If x>0 Then
value=0
y=InStr(s," ")
If y<x Then
value=CDbl(Left(s,y-1))
s=Trim(Mid(s,y))
x=InStr(s,"/")
End If
t=Left(s,x-1)
s=Mid(s,x+1)
If IsNumeric(s) And IsNumeric(t) Then
value=value+(CDbl(t)/CDbl(s))
s=Format(value,"#####.#####")
End If
End If
//
If Not IsNumeric(s) Then
error=True
Exit For
End If
value=CDbl(s)

Select Case unit
Case "'"
Case ChrB(34)
Case "y" // yards = 3 feet
Case "u" // mm
Case "c" // cm
Case "x" // meter
Case Else
error=True
Exit For
End Select
Next i

End Function``````

Feel free to use it in your own projects, just please give credit someplace

If you have improvements, please let me know so we can all benefit.

FYI… I also have a method for the OPPOSITE of this… value to string

What will happens if je donne une rponse en Franais ?

There are only some solutions: either you contine to use the Colonial neasures (inch, gallon, etc.) or you use the widely used (the rest of the world) measures.

Compare (apple and oranges) the date format:

a. YYYY/MM/DD, DD/MM/AAAA etc. (how many others ?
b. Jews use a value (> 6700), Muslims > 1400, Christians: 2018)

and I do not talk about the hours (is GMT still used ?)

Did I talk about the Franc ? (French money since and until 2002)
Old people (older than me, but not only) still use the way to talk that was in use before the 1958 (Old Franc), some still use the post 1958 value (/100 from the previous value).
Relative younger people use the (and mosy of Europe use Euro since 1999-01-01).

What a mess.

The only solution (for today as for tomorrow) is to use international (ISO) values, BUT always explain to the user your software deals with them.

After all, you put a stamp in a letter and it goes to destination (everywhere from your state/country to all continents
Same apply for the phone numbers !

Emile… I believe most of us are aware that the world uses various formats for almost everything,… however my posting was focused on DISTANCE, and for that there are just two MAJOR methods (yes, there are others, but they are not worth the effort to support in modern software…)

As a French man whose country invented the metric system, I can attest that we tend to always use decimal, and never fractions.

The most common small size value is centimeters, although very small sizes would in millimeters. Up to 50 centimeters, usually.

After that, meters are used.

In Europe, decimal separator is comma.

However, I noticed that Amazon uses the dot in Canada, and Mexico, both countries using Metric.

In Europe, thousands separators are less consistent. In France, thousands separator is the space character. In Switzerland, it is the apostrophe. In some other countries, dot is used.

as much I assumed… but since it was easier to just allow fractions regardless of Metric vs Imperial I did so.
The method I posted actually allows you to mix and match both systems, as it breaks the input string into individual components and evaluates each on its own merit.
so something like

``````dim error as boolean
call String2Dist("5 feet 3.7 inches 6 meters 3202 cm 5 yards 3 mm",error) ``````

and it SHOULD deal with comma vs dot correctly based on locale

While I doubt America will ever embrace the Metric system in day to day life… I do find it interesting how inconsistent the Imperial system is. Metric obviously is based on multiples of 10…
where the Imperial System is all over the place

fractions of inches are in multiples of 1/32 (for most measurements) 1/32, 1/16, 1/8, 1/4, 1/2 etc.
Feet are multiples of 12
Yards of multiples of 3 feet
Miles are 5280 feet

But when ever I run across Metric… I always need to convert in my head… remembering the magic number for the most part is 2.54, just remember where the decimal point goes

After some like ten years in the US, I had become fairly fluent at converting mentally. The only conversion I could not perform was Fahrenheit and Celsius

For a ‘close enough’ conversion (if I need a jacket or shorts), what I do is (F - 30) / 2 = C

After some practice you can play with the values, like 87, go to 90 - 30 = 60 / 2 = 30 when actually is 30.55.

Always good to read these kind of posts.
In Australia we use metric with a decimal point as seperator, not a comma.
Height is in cm e.g. 175 cm
Weight is in Kg e.g. 101.5

Distance is in Km, metres, cm
If measuring for carpentry, use mm
E.g, width of 20 mm length 1200 mm (1.2 m)

Note the use of capitals Vs lower case.
I have written an app to calculate heparin doses for patients undergoing radio frequency ablation for atrial fibrillation. It used height, weight, ■■■ to calculate an estimated blood volume.

I would be very interested to see Dave Ss reverse calculation from pounds and inches to Kg and cm

Right now the reverse of what I posted, it DISTANCE based only, but with proper incentive I could easily make an entire class that would do distance, weight and volume

Just reflecting on your original post Dave: I have a need to create a custom textfield that will accept a measurement, that can be in either Metric or Imperial (ft/inches)

Why not have two text fields, one for imperial and one for metric. You could then enforce the date entered to be if the format you desire, as indicated in your labels, then if the metric data field is entered, do the conversion and update the imperial display. If entered in the imperial field, update the metric one.

Either way, you can use the data from the imperial text field to do your calculations

As to an incentive, I can do your tadpole manual in .pdf HTML, word format. I havent forgotten, just been flat out like a lizard drinking on the app I am writing ( desktop and iOS versions)

My app isn’t a conversion program… It is a home design program, where the user might be in American and user Imperial measuements, or in Europe with Metric… So each textfield that accepts a measurement (height, width etc) can accept it either way, and internally store and do the math on “inches”… later spitting it back out in metric if asked to do so

Ok
How about a setup page where the user accepts a contract to use either metric or imperial as the default data entry? You could also check location and automatically determine if commas or decimal points should be used, although this may it be necessary as your conversion function could easily check for that