I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
COST (GBP)
this unit 6.00
sub units 0.00
+
0
UnitsConvert

convert

Converts any numbers from one unit to another
Controller: CodeCogs

Interface

C++

Convert

 
doubleconvertdoublenumber
unitsfrom_unit
unitsto_unit )
Converts numbers from one unit to another. This module acts as a unit converter, converting approximately 150 different units (see below).

This module is similar to the EXCEL convert function, only considerably smarter. Converts a number from one measurement system to another. For example, convert can translate a distance in miles to meters. There is a check that the requested input and output units are compatable i.e. it will not allow a length to be converted into a pressure.

Example 1

#include <iostream>
#include <codecogs/units/convert/convert.h>
using namespace Units;
int main()
{
  std::cout << "convert(10.2,unit_m, unit_ft)=" <<convert(10.2,unit_m, unit_ft);
  std::cout << "convert(123, unit_W, unit_HP)=" <<convert(123, unit_W, unit_hp);
 
  return 0;
}
Output:
convert(10.2,unit_m, unit_ft)= 33.46456693
  convert(123, unit_W, unit_HP)= 0.013678405

Note

Conversion between incompatible types will throw an error

References

http://www.unc.edu/~rowlett/units/index.html

Parameters

numberthe value in from_unit 's to convert
from_unitan enumerated value of the initial measurement type
to_unitan emuerated value of the output measurement type

Returns

the value in the converted unit.

Authors

realnero
Source Code

Source code is available when you buy a Commercial licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.


RecogniseUnit

 
intrecogniseUnitconst char*unit
float& hitrate )
This function attempts to recognise the unit within a character string. The function scans through a list of variable names and computes the percentage match. It returns the variable with the highest match, i.e. the closest unit to the string specified.

See:

Used by convert to recognises each of the two input strings.

Example 2

#include <iostream>
#include <codecogs/units/convert/convert.h>
 
int main()
{
   std::cout << "convert(10.2,\"meters\", \"feet\")=" << Units::convert(10.2,"meters", "feet");
   std::cout << "convert(123, \"W\", \"Horce power\")=" << Units::convert(123, "W", "Horce power");
 
   return 0;
}
Output:
convert(10.2,"meters", "feet")= 33.46456693
  convert(123, "W", "Horce power")= 0.013678405

Parameters

unitcharacter string containing a possible measurement unit
hitratethe computed accuracy of the match to a unit through this reference.

Authors

Will Bateman and Nick Owens
Source Code

Source code is available when you buy a Commercial licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.


RecognisePower

 
intrecognisePowerchar*& unit )
Recognises the power token for SI units within in a text string
long token short token power
exa E 18
peta P 15
tera T 12
giga G 9r
mega M 6
kilo k 3
hecto h 2
dekao e 1
deci d -1
centi c -2
milli m -3
micro u -6
nano n -9
pico p -12
femto f -15
atto a -18

Parameters

unitpointer to a text string containing possible power part for an SI unit. If a power is idenitified within the string, this pointer is advanced so that it points to the start of the subsequent unit.

Returns

the power of ten to which the SI unit is raised.
Source Code

Source code is available when you buy a Commercial licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.


Convert

 
doubleconvertdoublenumber
char*from_unitstr
char*to_unitstr )
Recognised the units within two character strings and converts the given number from one unit ito another. This routine tries to find the optimal match by calculating the most likely set of units from given text strings. To improve the matching, it is important that the initial spelling of the unit is correct (first 3-4 characters). The importance of subsequent letters becomes increasingly irrelevent.

Note

Conversion between incompatible types will return 0.

Parameters

numberthe value to convert
from_unitstran string value of the initial measurement type
to_unitstran string value of the output measurement type

Returns

the value in the converted unit.
Source Code

Source code is available when you buy a Commercial licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.


Other Documentation

The standard measurement units are:
Unit names Alternate names / spellings Abbreviation Enumeration Code Conversion Rate (relative to first unit)
Distance
Meter metre m unit_m 1
Feet Foot ft unit_ft 3.280839895
Furlongs Furlong fur unit_fur 0.00497097
Inches Inch in unit_in 39.37007874
Light years Lightyears ly unit_ly 1.06E-16
Miles Miles mile unit_mile 0.000621371
Nautical Miles Nautical Mile nmile unit_nmile 0.000539957
Parsecs Parsec psc unit_psc 3.24E-17
Yards Yard yd unit_yd 1.093613298
Flow
Litres/second Liters/second l/s unit_l_s 1
Feet3/hour Foot3/hour cu ft/hr unit_ft3_hr 127.1328002
Feet3/minute Foot3/minute cu ft/min unit_ft3_min 2.118880003
Feet3/second Foot3/second Cu ft/sec unit_ft3_sec 0.035314667
Gallons (UK)/day Gallon (UK)/day gal/da (UK) unit_gal_da_uk 19005.33469
Gallons (UK)/hour Gallon (UK)/hour gal/hr (UK) unit_gal_hr_uk 791.8889455
Gallons (UK)/minute Gallon (UK)/minute gal/min (UK) unit_gal_min_uk 13.19814909
Gallons (UK)/second Gallon (UK)/second gal/sec (UK) unit_gal_sec_uk 0.219969152
Gallons/day Gallon/day gal/da unit_gal_da 22824.46532
Gallons/hour Gallon/hour gal/hr unit_gal_hr 951.0193885
Gallons/minute Gallon/minute gal/min unit_gal_min 15.85032314
Gallons/second Gallon/second gal/sec unit_gal_sec 0.264172052
Litres/day Liters/day l/da unit_l_da 86400
Litres/hour Liters/hour l/hr unit_l_hr 3600
Litres/minute Liters/minute l/min unit_l_min 60
Meters3/day Metres3/day cu m/da unit_m3_da 86.4
Meters3/hour Metres3/hour cu m/hr unit_m3_hr 3.6
Meters3/minute Metres3/minute cu m/min unit_m3_min 0.06
Meters3/second Metres3/second cu m/sec unit_m3_sec 0.001
Ounces (UK)/hour Ounce (UK)/hour oz/hr (UK) unit_oz_hr_uk 126702.2313
Ounces (UK)/minute Ounce (UK)/minute oz/hr (UK) unit_oz_min_uk 2111.703855
Ounces (UK)/second Ounce (UK)/second oz/hr (UK) unit_oz-hr_uk 35.19506424
Ounces/hour Ounce/hour oz/hr unit_oz_hr 121730.4817
Ounces/minute Ounce/minute oz/min unit_oz_min 2028.841362
Ounces/second Ounce/second oz/sec unit_oz_sec 33.8140227
Yards3/hour Yard3/hour cu yd/hr unit_yd3_hr 4.70862223
Yards3/minute Yard3/minute cu yd/min unit_yd3_min 0.078477037
Yards3/second Yard3/second cu yd/sec unit_yd3_sec 0.001307951
Density
Grams/Meter3 Grams/Metre3 g/cu m unit_g_m3 1
Ounces/Gallon Ounce/Gallon Oz/gal unit_Oz_gal 0.000133526
Pounds/Foot3 Pounds/Feet3 lb/cu ft unit_lb_ft3 6.24E-05
Pounds/Inch3 Pound/Inch3 lb/cu in unit_lb_in3 3.61E-08
Tons/Yard3 Tonne/Yard3 T/cu yd unit_T_yd3 1.44E-06
Area
Meters2 Metres2 sq m unit_m2 1
Acres acre a unit_a 0.000247104
Feet2 foot2 sq ft unit_ft2 10.76391042
Hectares Hectare ha unit_ha 0.0001
Inches2 Inch2 sq in unit_in2 1550.0031
Miles2 Mile2 sq mi unit_mi2 3.86E-07
Yards2 Yard2 sq yd unit_yd2 1.195990046
Angle
Radians Radian rad unit_rad 1
Circles Circle cir unit_cir 0.159154943
Degrees Degree deg unit_deg 57.29577951
Grades Grade grd unit_grd 63.66197724
Minutes Minute min (angle) unit_min_angle 3437.746771
Octants Octant octant unit_octant 1.273239545
Revolutions Revolution rev unit_rev 0.159154943
Seconds Second sec unit_sec_angle 206264.8062
Turns Turn trn unit_trn 0.159154943
Quadrants Quadrant quad unit_quad 0.636619772
Acceleration
Meters/sec2 Metres/sec2 m/sq sec unit_m_sec2 1
Feet/sec2 foot/sec2 ft/sq sec unit_ft_sec2 3.280839895
Free fall (g) gravity g (grav) unit_grav 0.101971621
Inches/sec2 Inch/sec2 in/sq sec unit_in_sec2 39.37007874
Speed
Meters/second Metres/second m/sec unit_m_sec 1
Meters/minute Metres/minute m/min unit_m_min 60
Meters/hour Metres/hour m/hr unit_m_hr 3600
Feet/second foot/second ft/sec unit_ft_sec 3.280839895
Feet/minute foot/minute ft/min unit_ft_min 196.8503937
Feet/hour foot/hour ft/hr unit_ft_hr 11811.02362
Knots Knot kt unit_kt 1.943844492
Mach Machs Ma unit_Ma 0.003016955
Miles/second Mile/second mi/sec unit_mi_sec 0.000621371
Miles/minute Mile/minute mi/min unit_mi_min 0.037282272
Miles/hour Mile/hour mph unit_mph 2.236936292
Pressure
Pascals Pascal Pa unit_Pa 1
Atmospheres Atmosphere atm unit_atm 9.87E-06
Bars Bar bar unit_bar 1.00E-05
Cm of Mercury Cm Mercury cmHg unit_cmHg 0.000750062
Dynes/Centimeter2 Dynes/Centimetre2 dyn/sq cm unit_dyn_cm2 10
Inches of Mercury Inch of Mercury in Hg unit_inHg 0.0002953
Pounds/Foot2 Pounds/Feet2 lb/sq ft unit_lb_ft2 0.020885434
Pounds/Inch2 Pound/Inches2 PSI unit_PSI 0.000145038
Tons/Foot2 Tonnes/Feet2 T/sq ft unit_T_ft2 1.04E-05
Tons/Inch2 Tonnes/Inch2 T/sq in unit_T_in2 7.25E-08
Torrs Torr unit_Torr 0.007500617
Kilograms/Meter2 Kilograms/Metre2 kg/sq m unit_kg_m2 0.101971621
Power
Watts Watts W unit_W 1
British Thermal Unit/hour BTU/hour BTU/hr unit_BTU_hr 3.415179027
British Thermal Unit/minute BTU/minute BTU/min unit_BTU_min 0.05691965
British Thermal Unit/second BTU/second BTU/sec unit_BTU_sec 0.000948661
Calories/second Calorie/second cal/sec unit_cal_sec 0.239058511
Horsepower Horse power hp unit_hp 0.001341022
Pound-feet/minute Pound-foot/minute lb.ft/min unit_lb_ft_min 44.25372896
Pound-feet/second Pound-foot/second lb ft/sec unit_lb_ft_sec 0.737562149
Mass
Grams Gram g unit_g 1
Carats Carat ct unit_ct 5
Grains Grain gr unit_gr 15.43235835
Ounces Ounce oz unit_oz 0.035273962
Ounces (Troy) Troy Ounce oz t unit_oz_t 0.032150748
Pennyweights Pennyweight dwt unit_dwt 0.643014931
Pounds Pound lb unit_lb 0.002204623
Pounds (Troy) Troy Pound lb t unit_lb_t 0.002679229
Stones Stone St unit_St 0.000157473
Tons (metric) metric Tonne T (metric) unit_T_met 1.00E-06
Tons (imperial) english Tonnes T (imperial) unit_T_imp 1.10E-06
Light
Lux Lux lx unit_lx 1
Flames Flame fl unit_fl 0.02322576
Footcandles Feetcandles fc unit_fc 0.09290304
Meter-candles Metre-candles mc unit_mc 1
Force
Newtons Newton N unit_N 1
Gram Force Grams Force gf unit_gf 101.9716213
Joules/Centimeter Joules/Centimetre J/cm unit_J_cm 100
Joules/Meter Joules/Metre J/m unit_J_m 1
Ounce Force Ounces Force ozf unit_ozf 3.59694309
Pound Force Pounds Force lbf unit_lbf 0.224808943
Temperature
Celsius deg C C unit_C 1
Fahrenheit deg F F unit_F 1.8
Kelvin deg K K unit_K 1
Time
Seconds Second sec unit_sec 1
Centuries Century century unit_century 3.17E-10
Days Day da unit_da 1.16E-05
Decades Decade decade unit_decade 3.17E-09
Fortnights Fortnight fortnight unit_fortnight 8.27E-07
Hours Hour hr unit_hr 0.000277778
Leap-years Leap-year leap yr unit_leap_yr 3.16E-08
Millenniums Millennium millennium unit_millennium 3.17E-11
Minutes Minute min unit_min 0.016666667
Months (30 days) Month (30 days) mon unit_mon 3.86E-07
Weeks Week wk unit_wk 1.65E-06
Years Year yr unit_yr 3.17E-08
Volume
Litres Liters l unit_l 1
Inches3 Inch3 cu in unit_in3 61.02374409
Feet3 foot3 cu ft unit_ft3 0.035314667
Yards3 Yard3 cu yd unit_yd3 0.001307951
Cups Cup c unit_c 4.226752838
Gallons (US) Gallon (US) gal (US) unit_gal_us 0.264172052
Gallons (UK) Gallon (UK) gal (UK) unit_gal_uk 0.219969152
Meters3 Metre3 cu m unit_m3 0.001
Ounces (US) Ounce (US) fl oz (US) unit_fl_oz_us 33.8140227
Ounces (UK) Ounce (UK) fl oz (UK) unit_fl_oz_uk 35.19506424
Pints Pint pt unit_pt 2.113376419
Quarts Quart qt unit_qt 1.056688209
Tablespoons Tablespoon tbsp unit_tbsp 67.6280454
Teaspoons Teaspoon tsp unit_tsp 202.8841362
Volume - Dry
Litres (Dry) Liters l (Dry) unit_l_dry 1
Barrels Barrel bbl unit_bbl 0.008648489
Bushels (Dry) Bushel (Dry) bu unit_bu 0.028377592
Pecks Peck pk unit_pk 0.113510368
Pints (Dry) Pint (Dry) pt (Dry) unit_pt_dry 1.81616588
Quarts (Dry) Quart (Dry) qt (Dry) unit_qt_dry 0.90808294
Source Code

Source code is available when you buy a Commercial licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.