function unitconverterMain(mode){this.version='0.6';w=450;h=180;props=[];units=[];currentPropIdx=0;sliderMax=0;unitsFromParams=null;unitsToParams=null;valFrom=0;valTo=0;loadUnits();var s='';s+='
';s+='
';s+=getPropList(props);s+='
';s+='';s+='
a
';s+=getSliderHTML();s+='
';s+='
© 2016 MathsIsFun.com v'+this.version+'
';s+='
';document.write(s);document.getElementById('props').selectedIndex=8;onPropsChange();} function swapUnits(){var f=document.getElementById('units-from'),t=document.getElementById('units-to');var tmp=t.selectedIndex;t.selectedIndex=f.selectedIndex;f.selectedIndex=tmp;onFromUnitsChange();onToUnitsChange();resetSlider();} function onPropsChange(){currentPropIdx=document.getElementById('props').selectedIndex;var unitNames=[];var unitNamesOrdered=[];for(var i in units[currentPropIdx]){unitNames.push(units[currentPropIdx][i][0]);} var order=props[currentPropIdx][1];for(var i in order){if(unitNames[order[i]]) unitNamesOrdered.push(unitNames[order[i]]);} unitNames=null;var s=getConvertFieldHTML('value-from','onFromValueChange','units-from','onFromUnitsChange','units-from-desc',unitNamesOrdered)+ getConvertFieldHTML('value-to','onToValueChange','units-to','onToUnitsChange','units-to-desc',unitNamesOrdered);document.getElementById('unit-selection').innerHTML=s;document.getElementById('units-to').selectedIndex=1;onFromUnitsChange();onFromValueChange();onToUnitsChange();onToValueChange();document.getElementById('value-from').value=1;onFromValueChange();resetSlider();} function onFromValueChange(){var e=document.getElementById('value-from');valFrom=e.value||0;if(!unitsToParams||!unitsFromParams)return;document.getElementById('value-to').value=fmt(convert(valFrom,unitsFromParams,unitsToParams),15);resetSlider();} function onToValueChange(){var e=document.getElementById('value-to');valTo=e.value||0;if(!unitsToParams||!unitsFromParams)return;document.getElementById('value-from').value=fmt(convert(valTo,unitsToParams,unitsFromParams),15);resetSlider();} function getConversionParams(unitName){var propUnits=units[currentPropIdx];for(var i in propUnits){if(propUnits[i][0]==unitName){return propUnits[i];}} console.log("Unit "+unitName+" does not exist");return null;} function onFromUnitsChange(e){var e=document.getElementById('units-from');var n=e.value;unitsFromParams=getConversionParams(n);document.getElementById("units-from-desc").innerHTML=unitsFromParams[1];onFromValueChange();} function onToUnitsChange(e){var e=document.getElementById('units-to');var n=e.value;unitsToParams=getConversionParams(n);document.getElementById("units-to-desc").innerHTML=unitsToParams[1];onFromValueChange();} function celsiusToFahrenheit(c){return c*9/5+32;} function fahrenheitToCelsius(f){return(f-32)*5/9;} function convert(fromVal,fromParams,toParams){if((fromParams[0]=="Degrees Celsius")&&(toParams[0]=="Degrees Fahrenheit")){return celsiusToFahrenheit(fromVal);} else if((toParams[0]=="Degrees Celsius")&&(fromParams[0]=="Degrees Fahrenheit")){return fahrenheitToCelsius(fromVal);} var v=Number(fromVal);var m=Number(fromParams[2])/Number(toParams[2]);if(isNaN(v))return "...........................";return v*m;} function getPropList(props){var s='';s+='';return s;} function getDropdownHTML(opts,funcName,id){var s='';s+='';return s;} function resetSlider(){var el=document.getElementById('slider');el.value=.5;sliderMax=document.getElementById('value-from').value*2;onSliderChange();} function onSliderChange(){var el=document.getElementById('slider');var aVal=sliderMax*el.value;var bVal=convert(aVal,unitsFromParams,unitsToParams);document.getElementById('slidefull').innerHTML=fmt(aVal,15)+' '+unitsFromParams[1]+' = '+fmt(bVal,15)+' '+unitsToParams[1];} function getSliderHTML(){var s='
'+ '
'+ ''+ '
';return s;} function getConvertFieldHTML(inputId,inputFunc,dropdownId,dropdownFunc,postFixId,opts){var s='
'+ '
'+ ''+ 'xxx'+ '
'+ getDropdownHTML(opts,dropdownFunc,dropdownId)+ '
';return s;} function loadUnits(){props.push([["Acceleration",""],[4,1,3,0],false]);units.push([["Foot/sec-squared","ft/sec²",0.3048],["G Force","g",9.80665],["Galileo","gal",0.01],["Inch/sec-squared","in/sec²",0.0254],["Meter/sec-squared","m/sec²",1]]);props.push([["Angles",""],[2,3,0],false]);units.push([["Degrees","°",0.01745329251994329576923690768489],["Gradian","gon",0.0157079632679489661923132169164],["Radian","rad",1],["Turns","r",6.283185307179586476925286766559]]);props.push([["Area",""],[8,5,9,11,10,13,12,0],false]);units.push([["Acre (intl)","acre",4046.8564224],["Acre (US)","acre",4046.872609874252],["Are","",100],["Barn","b","1e-28"],["Circular mil","","5.067075e-10"],["Hectare","ha",10000],["Rood","",1011.7141056],["Square centimeter","cm²",0.0001],["Square meter","m²",1],["Square kilometer","km²",1000000],["Square foot","ft²",0.09290304],["Square inch","in²",0.00064516],["Square mile","mi²",2589988.110336],["Square yard","yd²",0.83612736]]);props.push([["Density",""],[2,1,6,7,11],false]);units.push([["Grain/gallon","",0.01711806],["Grams/cm³","g/cm³",1000],["Kilogram/cub.meter","kg/m³",1],["Ounces/gallon (UK,liq)","",6.236023],["Ounces/gallon (US,liq)","",7.489152],["Ounces (mass)/cubic inch","",1729.994],["Pound mass/cubic foot","",16.01846],["Pound mass/cubic-inch","",27679.91],["Pound mass/gal (UK,liq)","",99.77637],["Pound mass/gal (US,liq)","",119.8264],["Slug/cubic foot","",515.379],["Tons (long,mass)/cub.yard","",1328.939]]);props.push([["Electricity",""],[1,2,3,4,5],false]);units.push([["Abcoulomb","",10],["Ampere hour","A hr",3600],["Coulomb","C",1],["Faraday","F",96485.3365],["Millifaraday","mF",96.4853365],["Microfaraday","µF",0.0964853365],["Picofaraday","pF",0.0000964853365],["Statcoulomb","","3.33564e-10"]]);props.push([["Energy",""],[12,11,7,14,3,0,6],false]);units.push([["BTU (SI)","BTU_IT",1055.05585262],["BTU (thermo)","BTU_th",1054.35],["Calorie (15°C)","cal_15",4.1858],["Calorie (Food)","kcal_th",4184],["Calorie (SI)","cal_IT",4.1868],["Calorie (thermo)","cal_th",4.184],["Electron volt","eV","1.602176487e-19"],["Erg","erg","1e-7"],["Foot-pound force","",1.355818],["Foot-poundal","",0.04214011],["Horsepower-hour","",2684519.537696172792],["Joule","J",1],["kiloJoule","kJ",1000],["Kilocalorie (SI)","kcal_IT",4186.8],["Kilowatt-hour","kWh",3600000],["Ton of TNT","","4.2e+9"],["Volt-coulomb","V Cb",1],["Watt-hour","Wh",3600],["Watt-second","Ws",1]]);props.push([["Force",""],[4,1,6,0],false]);units.push([["Dyne","dy",0.00001],["Kilogram force","kgf",9.80665],["Kilopond","kp",9.80665],["Kip","k",4448.2216152605],["Newton","N",1],["Ounce force","ozf",0.27801385095378125],["Pound force","lbf",4.4482216152605],["Poundal","",0.138254954376]]);props.push([["Force per length",""],[0,1,2],false]);units.push([["Newton/meter","N/m",1],["Pound force/inch","lbf/in",175.1268],["Pound force/foot","lbf/ft",14.5939]]);props.push([["Length",""],[12,11,2,3,7,6,20,14],false]);units.push([["Angstrom","Å","1e-10"],["Astronomical unit","AU","1.49598e+11"],["Centimeter","cm",0.01],["Kilometer","km",1000],["Fathom","",1.8288],["Furlong","",201.168],["Foot","ft",0.3048],["Inch","in",0.0254],["Light year","LY","9.4607304725808e+15"],["Micrometer (µm)","",0.000001],["Mil","",0.0000254],["Millimeter","mm",0.001],["Meter","m",1],["Nanometer","nm","1e-9"],["Mile","mi",1609.344],["Nautical Mile","",1852],["Parsec","","3.085677581e+16"],["Picometer","pm","1e-12"],["Point","pt",0.0003514598],["Rod","",5.0292],["Yard","yd",0.9144]]);props.push([["Light",""],[5,2,0,6],false]);units.push([["Foot-candle","ft-cdl",10.76391],["Foot-lambert","",10.76391],["Lumen/sq.meter","Lu/m²",1],["Lumen/sq.centimeter","Lu/cm²",10000],["Lumen/sq.foot","Lu/ft²",10.76391],["Lux","lux",1],["Phot","ph",10000]]);props.push([["Mass",""],[4,1,7,9,15,14,13],false]);units.push([["Carat (metric)","ct",0.0002],["Gram","g",0.001],["Hundredweight (long)","",50.80235],["Hundredweight (short)","",45.35924],["Kilogram","kg",1],["Microgram","µg","1e-9"],["Milligram","mg",0.000001],["Ounce mass","oz",0.028349523125],["Ounce mass (troy)","",0.03110348],["Pound mass","lb",0.45359237],["Pound mass (troy)","",0.3732417],["Slug","",14.5939],["Ton (assay)","",0.02916667],["Ton (long)","",1016.047],["Ton (short)","",907.1847],["Tonne (metric ton)","t",1000]]);props.push([["Mass Flow",""],[0,1,2],false]);units.push([["Kilogram/second","kg/s",1],["Pound mass/sec","lbm/s",0.4535924],["Pound mass/min","lbm/min",0.007559873]]);props.push([["Power",""],[20,17,18,11,4,0],false]);units.push([["BTU (SI)/hour","",0.2930711],["BTU (thermo)/second","",1054.35],["BTU (thermo)/minute","",17.5725],["BTU (thermo)/hour","",0.2928751],["Calorie (thermo)/second","",4.184],["Calorie (thermo)/minute","",0.06973333],["Erg/second","","1e-7"],["Foot-pound force/hour","",0.0003766161],["Foot-pound force/minute","",0.02259697],["Foot-pound force/second","",1.355818],["Horsepower (550 ft lbf/s)","",745.69987158227022],["Horsepower (electric)","",746],["Horsepower (boiler)","",9809.5],["Horsepower (metric)","",735.49875],["Horsepower (UK)","",745.7],["Kilocalorie (thermo)/min","",69.7333],["Kilocalorie (thermo)/sec","",4184],["Kilowatt","kW",1000],["Megawatt","MW",1000000],["Milliwatt","mW",0.001],["Watt","W",1]]);props.push([["Pressure & Stress",""],[6,10,12,18,17,2],false]);units.push([["Atmosphere (normal)","atm",101325],["Atmosphere (technical)","",98066.5],["Bar","",100000],["Centimeter mercury","cmHg",1333.22],["Centimeter water (4°C)","",98.0638],["Decibar","",10000],["Kilopascal","kPa",1000],["kg force/sq.centimeter","kgf/cm²",98066.5],["kg force/sq.meter","kgf/m²",9.80665],["Kip/square inch","",6894757],["Megapascal","MPa",1000000],["Millibar","mbar",100],["Millimeter mercury","mmHg",133.3224],["Newton/sq.meter","N/m²",1],["Pascal","Pa",1],["Poundal/sq.foot","",1.488163943569553806],["Pound-force/sq.foot","",47.88026],["Pound-force/sq.inch","psi",6894.757],["Torr (mmHg,0°C)","",133.322]]);props.push([["Temperature",""],[0,1],true]);units.push([["Degrees Celsius","°C",1,0],["Degrees Fahrenheit","°F",0.5555555555555555555555,-32],["Degrees Kelvin","K",1,-273.15],["Degrees Rankine","R",0.55555555555555555555555,-491.67]]);props.push([["Time",""],[7,4,2,0,9,10,11],false]);units.push([["Day","d",86400],["Day (sidereal)","d(sid)",86164.09],["Hour","h",3600],["Hour (sidereal)","h(sid)",3590.170416667],["Minute","min",60],["Minute (sidereal)","m(sid)",59.836173611],["Month (mean calendar)","month(mean)",2628000],["Second","s",1],["Second (sidereal)","s(sid)",0.9972696],["Year (calendar)","y",31536000],["Year (tropical)","y(trop)",31556930],["Year (sidereal)","y(sid)",31558150]]);props.push([["Torque",""],[4,1,2,3],false]);units.push([["Dyne-centimeter","dy cm","1e-7"],["Kg force-meter","kgf m",9.80665],["Pound force-inch","lbf in",0.1129848],["Pound force-foot","lbf ft",1.355818],["Newton-meter","N m",1]]);props.push([["Velocity & Speed",""],[4,2,1,6,8,3,10],false]);units.push([["Foot/minute","ft/min",0.00508],["Foot/second","ft/sec",0.3048],["Kilometer/hour","km/h",0.27777777777777777778],["Knot (int'l)","kn",0.514444444444444444444444444444],["Meter/second","m/s",1],["Mach (STP)(a)","mach",340.006875],["Mile (US)/hour","mph",0.44704],["Mile (US)/minute","mi/min",26.8224],["Mile (US)/second","mi/sec",1609.344],["Nautical Mile/hour","kn",0.514444444444444444444444444444],["Speed of light","c",299792458]]);props.push([["Volume & Capacity",""],[15,4,9,8,11,19,14],false]);units.push([["Acre-foot","",1233.48183754752],["Barrel (oil)","bbl",0.1589873],["Board foot (FBM)","",0.002359737],["Bushel (US)","",0.03523907],["Cubic Meter","m³",1],["Cubic centimeter","cm³",0.000001],["Cubic millimeter","mm³","1e-9"],["Cup","",0.0002365882],["Cubic foot","cu ft",0.02831685],["Cubic inch","in³",0.00001638706],["Cubic yard","cu yd",0.7645549],["Fluid Ounce (US)","fl.oz.",0.00002957353],["Gallon (UK)","gal",0.004546087],["Gallon (US, dry)","gal",0.004404884],["Gallon (US, liq)","gal",0.003785412],["Liter","L",0.001],["milliliter","ml",0.000001],["Peck (US)","",0.008809768],["Pint (US, dry)","pt",0.0005506105],["Pint (US, liquid)","pt",0.0004731765],["Quart (US, dry)","qt",0.001101221],["Quart (US, liquid)","qt",0.000946353],["Tablespoon","tbs",0.00001478676],["Teaspoon","tsp","4.928922e-6"]]);props.push([["Volume Flow",""],[5,3,4,0,1],false]);units.push([["Cubic foot/second","ft³/s",0.02831685],["Cubic foot/minute","ft³/min",0.0004719474],["Cubic inches/minute","","2.731177e-7"],["Cubic meter/second","m³/s",1],["Gallons (US,liq)/minute)","",0.0000630902],["Liters/second","L/s",0.001]]);} function fmt(num,digits){if(num==Number.POSITIVE_INFINITY) return "undefined";if(num==Number.NEGATIVE_INFINITY) return "undefined";num=num.toPrecision(digits);num=num.replace(/0+$/,"");if(num.charAt(num.length-1)==".")num=num.substr(0,num.length-1);if(Math.abs(num)<1e-15)num=0;return num;}