Where can I find a good C# library that does basic unit conversions (US Standard to/from SI among other things)?
Anyway, I need a C# library to do unit conversions. I have 5 categories I need to deal with converting: Distance (miles, inches, kilometers, centimeters, etc.); Speed (MPH, mps, etc.); Pressure (Barometric) (Hg, hPa, mb, etc.); Temperature (C, F, K); and Time Zones (Eastern, Central, Daylight Savings, international, etc.)
I am open to all forms of processing (regular expressions, object-oriented, static methods, etc.). I have not entirely decided how to expose the library to my existing code base. My initial thought was a large set of static methods separated into several classes (long meters = Distance.ConvertFeetToMeters(elevationInFeet);).
Due to customer requests, the library should adhere exactly to current NIST regulations for applicable conversions. Documentation showing this is a definite plus.
I am considering writing all this myself, but it might be easier (and more respected) if I get an existing library from an authoritative source (like NIST). In addition, reviewing other libraries might give me a good idea of alternative format options for exposing the library to my code base or writing my own.
You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.
M$4 Answers
I guess the author would maybe willing to license the code for your usage for a reasonable amount.
This would resolve the issues with more or less open sources. Besides, this software was created 10 years ago and has been improved ever since. I consider it to be reliable, which is important if you don't have time to check and validate all conversion pairs one by one...
I hope this helps, even if it is slightly out of topic.
I underline I have no connection at all with the author of this SW.
You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.
M$http://www.boost.org/doc/libs/1_40_0/doc/html/boost_units/Units.html
You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.
M$Can you please offer more information about the library?
Is the code available or is it just the compiled libraries? What language is it written in? What licenses apply to it? What standards does it follow? How well does it compare to the conversion categories I have listed above? What does the interface look like? Have you had any personal experience with using it? Do you know anyone else who uses it?
Please expand your answer.
The boost library is pretty much a standard these days. I thought I gave you the link to the c# version. But its c++. Sorry about that.
In C# the approach is somewhat simplified. There are a number of unit conversion libs. They provide the mechanism so that for any specific unit the only thing that needs to be added is the mapping from one unit to another.
E.g. http://www.codeproject.com/KB/library/Measurement_Conversion.aspx
which is licensed under the CPOL - which looks suitable for you.
For timezones you need a different approach because it's not a linear conversion.
This is implemented in C# .net 3.5 - if you are using that then just use the TimeZoneInfo class
http://pietschsoft.com/post/2007/06/23/NET-35-How-to-Convert-from-one-TimeZone-to-another.aspx
http://msdn.microsoft.com/en-us/library/system.timezoneinfo%28VS.90%29.aspx
Of course .net also has a units conversion library called UnitConvert Table.
But you will need to (as in above example) fill in the factors for the units you wan t to use.
http://msdn.microsoft.com/en-us/library/aa886418.aspx
Thank you for the dialog. I appreciate the suggestions. I did give a small tip for them. However, I did not select your answer for best answer because I felt the level of detail you included did not warrant the full tip for the original question.
In addition, the Measurement Conversion ZIP files seem to be corrupted. When I download them, my computers say the folders cannot be unzipped because they are empty. (I have tried using XP and Win7.)
An old unit of area used for measuring the area of land . The acre (old English word meaning field) was originally defined as the area that could be plowed in a day by a yoke of oxen. The acre was defined as the area of a field one furlong long by 1/10 furlong wide. In metric the unit corresponding to the acre is the hectare, which is 10,000 square metre. One acre is equal to 0.404 687 3 hectare.
ampere (A or amp) The SI base unit of electric current, named after the French physicist André-Marie Ampère (1775-1836). The ampere is defined as the constant current which, if maintained in two straight parallel conductors of infinite length, of negligible circular cross-section, and placed 1 metre apart in vacuum, would produce between these conductors a force equal to 2 x 10-7 newton per metre of length.
ampere hour (Ah or amp hr )
A unit of electric charge often used to state the capacity of a battery. One ampere hour is the charge accumulated by a steady flow of one ampere for one hour. This is equivalent to exactly 3600 coulomb.
ampere per meter (A/m)
The SI derived unit of magnetic field strength.
angstrom (Å) convert
A metric unit of length, equal to 0.1 nanometre or 10-10 metre. Angstrom unit named after the Swedish physicist Anders Jon Ångström (1814-1874) and is used most often to measure extremely small lengths like the wave length of light.
arcminute (' , min) convert
A unit of angle measurement, also called the minute of arc, equal to 60 arcseconds and to 1/60 degree. There are 21 600 arcminutes in a circle. Care is needed not to confuse symbols with units of length or time. The SI recommends ' as the symbol for arcminute.
arcsecond (",sec, s, as) convert
A unit of angle measure, also called the second of arc, equal to 1/60 arcminute. One arcsecond is a very small angle: there are 1 296 000 seconds in a circle. Care is needed not to confuse symbols with units of length or time. The SI defines s as the symbol for the time unit and recommends " as the symbol for the arcsecond.
are (a)
An old unit of area equal to 100 square metre.
astronomical unit (ua or au or AU) convert
A unit of distance used by astronomers to measure distances in the Solar System. One astronomical unit equals the average distance from the centre of the Earth to the centre of the Sun. The currently accepted value is 1.495 978 x 1011 metre or about 92 955 807 miles. The astronomical unit is a convenient yardstick for measuring the distances between objects in the Solar System. This unit is accepted for use with SI units.
atmosphere (atm) convert
A unit of pressure equal the average pressure of the Earth's atmosphere at sea level. One atmosphere is equal to 1.013 25 bar or 1.013 25 x 105 Pa or 760 mmHg.
atomic mass unit (u)
The unit of mass used for measuring the masses of atoms and molecules. Originally these relative masses were based on hydrogen, known to be the lightest element, having a mass of 1 u, and all the other atoms should have masses which are whole-number multiples of this (then unknown) mass of the hydrogen atom. Since 1960 the unified atomic mass unit has been defined as 1/12 the mass of the carbon-12 atom. 1u = 1.66 x 10-27 kg.
atomic number
A unit of measurement, equal to the number of electrons surrounding a neutral (uncharged) atom, and also to the number of protons in the nucleus. The atomic number was originally defined simply as an index describing the position of an element in the periodic table.
Avogadro constant (NA), Avogadro's number
A unit of relative quantity equal to the number of atoms or molecules per mole of a substance. The currently accepted value is 6.022 1415 x 1023 per mole. The atomic mass unit in grams, is equal to one divided by this number. The unit is named after the Italian chemist and physicist Amadeo Avogadro (1776-1856). Avogadro was the first to conclude from Dalton's atomic theory that equal volumes of gases (at the same temperature and pressure) must contain equal number of molecules.
bar (bar) convert
A unit of pressure, equal to 105 pascal. One bar is roughly the same as the average pressure of the Earth's atmosphere (atm), which is 1.013 25 bar. A barometer an instrument for measuring barometric pressure of the atmosphere, usually in units of millibar (mbar) or as the height in millimetres, of a column of mercury (mmHg).
barn (b)
A unit of area used in nuclear physics. One barn is equal to 10-28 square metre or 100 square femtometre.
becquerel (Bq)
The SI derived unit of activity, usually meaning radioactivity. One becquerel is the radiation caused by one disintegration per second. The unit is named after the French physicist, Antoine-Henri Becquerel (1852-1908), the discoverer of radioactivity. Note: both the becquerel and the hertz are basically defined as one event per second, yet they measure different things.
bel (B)
A logarithmic measure of sound intensity, invented by engineers of the Bell telephone network in 1923 and named after the inventor of the telephone, Alexander Graham Bell (1847-1922). The scale is logarithmic; if the difference in sound intensity is 1 bel the difference is 10 times and 2 bels corresponds to an increase of 10 x 10 or 100 times in intensity. The beginning of the scale, 0 bels, was originally intended to represent the faintest sound that people can hear. In practice, sound intensity is almost always stated in decibels. One bel is equal to approximately 1.151 293 nepers.
bohr radius (a0)
A unit of distance used in particle physics. The bohr radius represents the mean distance between the proton and the electron in an unexcited hydrogen atom. It equals about 52.918 picometre (pm), or 52.918 x 10-12 metre. The unit was named after the Danish physicist Niels Bohr (1885-1962).
boltzmann's constant (k)
The number that relates the average energy of a molecule to its absolute temperature. Boltzmann's constant is approximately 1.38 × 10-23 J/K. British thermal unit (Btu or BTU) convert
A unit of heat energy defined as the amount of heat required to raise the temperature of one pound of water by one degree Fahrenheit. Like the calorie below Btu can have slightly different values, so for accurate work it is necessary to specify which is being used.
* BtuIT = 1055.056 J
* Btuth = 1054.350 J
* Btumean = 1055.87 J
You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.
M$http://www.boost.org/doc/libs/1_40_0/doc/html/boost_units/Units.html
You can leave an optional "tip" with Mahalo's virtual currency, Mahalo Dollars. If you are asking a difficult question that might require some research, or if you'd like a wide variety of feedback, a higher tip often leads to more answers to your question.
M$Can you please offer more information about the library?
Is the code available or is it just the compiled libraries? What language is it written in? What licenses apply to it? What standards does it follow? How well does it compare to the conversion categories I have listed above? What does the interface look like? Have you had any personal experience with using it? Do you know anyone else who uses it?
Please expand your answer.
Thank you, this seems like a very good application.
However, with a large variety of open libraries available, I am afraid I would have a hard time convincing my boss to go the route of contacting an individual who offers a freeware application to see if we can license his source code.