Unit conversions?

Does anyone know of a class for converting values between units in real and or string formats?
Eg:
String s = "1'-10\"";
double f = Convert(s);
// now f = 1.8333
String sr = Convert(f);
// now sr = 1'-10"
Any ideas?
Mike B
[284 byte] By [MikeB] at [2007-11-20 9:32:16]
# 1 Re: Unit conversions?
String s = "1'-10\"";

Apologies if this a daft question but is that meant to be feet and inches or have I got the wrong end of the ruler?
Rich2189 at 2007-11-9 11:34:18 >
# 2 Re: Unit conversions?
String s = "1'-10\"";

Apologies if this a daft question but is that meant to be feet and inches or have I got the wrong end of the ruler?
Yes, I am working on an application that uses linear measurements in both metric an imperial units. Although it is easy enough to convert between the units, I am not sure on how to convert between the real and string representation of these measurements. I have a hard time believing that this was not done before, but, I cannot find anything similar...

Mike B
MikeB at 2007-11-9 11:35:19 >
# 3 Re: Unit conversions?
Ah I see, I'm working on a calculator at the moment that takes the input in the form "((5+4)*4)^2" etc. The best way would be to split the unit into its component parts feet and inches. Then you can use the ' and '' to determine what type of unit your dealing with.

1'-10\" Split about the "-"

Read the last char in the first string, in this case it is ', meaning its feet and inches.

You can use Convert.ToDouble() to get convert a string to a double after removing the units from each of the two strings.

divide the second string by 12 to give the decimal. 10/12 = 0.8333333

Add the first string to it to give 1.8333333.
Rich2189 at 2007-11-9 11:36:29 >
# 4 Re: Unit conversions?
Ah I see, I'm working on a calculator at the moment that takes the input in the form "((5+4)*4)^2" etc. The best way would be to split the unit into its component parts feet and inches. Then you can use the ' and '' to determine what type of unit your dealing with.

1'-10\" Split about the "-"

Read the last char in the first string, in this case it is ', meaning its feet and inches.

You can use Convert.ToDouble() to get convert a string to a double after removing the units from each of the two strings.

divide the second string by 12 to give the decimal. 10/12 = 0.8333333

Add the first string to it to give 1.8333333.

Thanks for the post. I understand what you are saying, I did something similar in an application before. What the real problem is however, I am trying to determine how to allow the user to type in a value and show the value that he/she may want to display.

I guess I am going to have to know a couple of things, what units were input, format of input, units of output, and the format of output.

format being 1 of the 4

decimal 1.8333 (Metric or SI)
engineering 1'-0.8333" (Only SI),
architectural 1'-10" (Only SI).
fractional 1 5/6 (metric or SI)

I guess I will also need a precision for rounding, especially for fractional formatting. OK, well, time to get to work, I guess I will have to cook-up my own!

Thanks :)

Mike B
MikeB at 2007-11-9 11:37:24 >
# 5 Re: Unit conversions?
Yeah, just wack a couple of combo boxes onto your form, and let the user select what they want. The fractional one will be interesting, its something I need to look into for the calculator.
Rich2189 at 2007-11-9 11:38:23 >
# 6 Re: Unit conversions?
Yeah, just wack a couple of combo boxes onto your form, and let the user select what they want. The fractional one will be interesting, its something I need to look into for the calculator.
Well, it shouldn't take long to do something with it, once I have something, I will post it and maybe you can use it.... :)

Mike
MikeB at 2007-11-9 11:39:23 >