Built-in Units

MathParser.org - mXparser - logo - Tutorial

*** If you found the software useful donation is something you might consider 🙂 ***

If you found the software useful donation is something you might consider :-)

JAVA code

Case 1: Units of length / distance

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("( 95*[cm] + 200*[m] + 1*[km] ) / [km]");
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate() );
[mXparser-v.4.0.0] Res: ( 95*[cm] + 200*[m] + 1*[km] ) / [km] = 1.20095

Case 2: Units of time

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("( 60*[min] + 2*[h] ) / [h]");
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate() );
[mXparser-v.4.0.0] Res: ( 60*[min] + 2*[h] ) / [h] = 3.0

Case 3: Units of information

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("8*[Mb] / [MB]");
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate() );
[mXparser-v.4.0.0] Res: 8*[Mb] / [MB] = 1.0

Case 4: Units of volume

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("2000*[l] / [m3]");
mXparser.consolePrintln("Res: " + e.getExpressionString() + " = " + e.calculate() );
[mXparser-v.4.0.0] Res: 2000*[l] / [m3] = 2.0

Case 5: List of supported units

import org.mariuszgromada.math.mxparser.*;
...
mXparser.consolePrintHelp("unit");
  128. ulp                 <Unary Function>        (3.0) Unit in The Last Place - ulp(0.1)
  235. [au]                <Constant Value>        (4.0) <Astronomical Constant> Astronomical unit [m] (m=1)
  307. [%]                 <Unit>                  (4.0) <Ratio, Fraction> Percentage = 0.01
  308. [%%]                <Unit>                  (4.0) <Ratio, Fraction> Promil, Per mille = 0.001
  309. [Y]                 <Unit>                  (4.0) <Metric prefix> Septillion / Yotta = 10^24
  310. [sept]              <Unit>                  (4.0) <Metric prefix> Septillion / Yotta = 10^24
  311. [Z]                 <Unit>                  (4.0) <Metric prefix> Sextillion / Zetta = 10^21
  312. [sext]              <Unit>                  (4.0) <Metric prefix> Sextillion / Zetta = 10^21
  313. [E]                 <Unit>                  (4.0) <Metric prefix> Quintillion / Exa = 10^18
  314. [quint]             <Unit>                  (4.0) <Metric prefix> Quintillion / Exa = 10^18
  315. [P]                 <Unit>                  (4.0) <Metric prefix> Quadrillion / Peta = 10^15
  316. [quad]              <Unit>                  (4.0) <Metric prefix> Quadrillion / Peta = 10^15
  317. [T]                 <Unit>                  (4.0) <Metric prefix> Trillion / Tera = 10^12
  318. [tril]              <Unit>                  (4.0) <Metric prefix> Trillion / Tera = 10^12
  319. [G]                 <Unit>                  (4.0) <Metric prefix> Billion / Giga = 10^9
  320. [bil]               <Unit>                  (4.0) <Metric prefix> Billion / Giga = 10^9
  321. [M]                 <Unit>                  (4.0) <Metric prefix> Million / Mega = 10^6
  322. [mil]               <Unit>                  (4.0) <Metric prefix> Million / Mega = 10^6
  323. [k]                 <Unit>                  (4.0) <Metric prefix> Thousand / Kilo = 10^3
  324. [th]                <Unit>                  (4.0) <Metric prefix> Thousand / Kilo = 10^3
  325. [hecto]             <Unit>                  (4.0) <Metric prefix> Hundred / Hecto = 10^2
  326. [hund]              <Unit>                  (4.0) <Metric prefix> Hundred / Hecto = 10^2
  327. [deca]              <Unit>                  (4.0) <Metric prefix> Ten / Deca = 10
  328. [ten]               <Unit>                  (4.0) <Metric prefix> Ten / Deca = 10
  329. [deci]              <Unit>                  (4.0) <Metric prefix> Tenth / Deci = 0.1
  330. [centi]             <Unit>                  (4.0) <Metric prefix> Hundredth / Centi = 0.01
  331. [milli]             <Unit>                  (4.0) <Metric prefix> Thousandth / Milli = 0.001
  332. [mic]               <Unit>                  (4.0) <Metric prefix> Millionth / Micro = 10^-6
  333. [n]                 <Unit>                  (4.0) <Metric prefix> Billionth / Nano = 10^-9
  334. [p]                 <Unit>                  (4.0) <Metric prefix> Trillionth / Pico = 10^-12
  335. [f]                 <Unit>                  (4.0) <Metric prefix> Quadrillionth / Femto = 10^-15
  336. [a]                 <Unit>                  (4.0) <Metric prefix> Quintillionth / Atoo = 10^-18
  337. [z]                 <Unit>                  (4.0) <Metric prefix> Sextillionth / Zepto = 10^-21
  338. [y]                 <Unit>                  (4.0) <Metric prefix> Septillionth / Yocto = 10^-24
  339. [m]                 <Unit>                  (4.0) <Unit of length> Metre / Meter (m=1)
  340. [km]                <Unit>                  (4.0) <Unit of length> Kilometre / Kilometer (m=1)
  341. [cm]                <Unit>                  (4.0) <Unit of length> Centimetre / Centimeter (m=1)
  342. [mm]                <Unit>                  (4.0) <Unit of length> Millimetre / Millimeter (m=1)
  343. [inch]              <Unit>                  (4.0) <Unit of length> Inch (m=1)
  344. [yd]                <Unit>                  (4.0) <Unit of length> Yard (m=1)
  345. [ft]                <Unit>                  (4.0) <Unit of length> Feet (m=1)
  346. [mile]              <Unit>                  (4.0) <Unit of length> Mile (m=1)
  347. [nmi]               <Unit>                  (4.0) <Unit of length> Nautical mile (m=1)
  348. [m2]                <Unit>                  (4.0) <Unit of area> Square metre / Square meter (m=1)
  349. [cm2]               <Unit>                  (4.0) <Unit of area> Square centimetre / Square centimeter (m=1)
  350. [mm2]               <Unit>                  (4.0) <Unit of area> Square millimetre / Square millimeter (m=1)
  351. [are]               <Unit>                  (4.0) <Unit of area> Are (m=1)
  352. [ha]                <Unit>                  (4.0) <Unit of area> Hectare (m=1)
  353. [acre]              <Unit>                  (4.0) <Unit of area> Acre (m=1)
  354. [km2]               <Unit>                  (4.0) <Unit of area> Square kilometre / Square kilometer (m=1)
  355. [mm3]               <Unit>                  (4.0) <Unit of volume> Cubic millimetre / Cubic millimeter (m=1)
  356. [cm3]               <Unit>                  (4.0) <Unit of volume> Cubic centimetre / Cubic centimeter (m=1)
  357. [m3]                <Unit>                  (4.0) <Unit of volume> Cubic metre / Cubic meter (m=1)
  358. [km3]               <Unit>                  (4.0) <Unit of volume> Cubic kilometre / Cubic kilometer (m=1)
  359. [ml]                <Unit>                  (4.0) <Unit of volume> Millilitre / Milliliter (m=1)
  360. [l]                 <Unit>                  (4.0) <Unit of volume> Litre / Liter (m=1)
  361. [gall]              <Unit>                  (4.0) <Unit of volume> Gallon (m=1)
  362. [pint]              <Unit>                  (4.0) <Unit of volume> Pint (m=1)
  363. [s]                 <Unit>                  (4.0) <Unit of time> Second (s=1)
  364. [ms]                <Unit>                  (4.0) <Unit of time> Millisecond (s=1)
  365. [min]               <Unit>                  (4.0) <Unit of time> Minute (s=1)
  366. [h]                 <Unit>                  (4.0) <Unit of time> Hour (s=1)
  367. [day]               <Unit>                  (4.0) <Unit of time> Day (s=1)
  368. [week]              <Unit>                  (4.0) <Unit of time> Week (s=1)
  369. [yearj]             <Unit>                  (4.0) <Unit of time> Julian year = 365.25 days (s=1)
  370. [kg]                <Unit>                  (4.0) <Unit of mass> Kilogram (kg=1)
  371. [gr]                <Unit>                  (4.0) <Unit of mass> Gram (kg=1)
  372. [mg]                <Unit>                  (4.0) <Unit of mass> Milligram (kg=1)
  373. [dag]               <Unit>                  (4.0) <Unit of mass> Decagram (kg=1)
  374. [t]                 <Unit>                  (4.0) <Unit of mass> Tonne (kg=1)
  375. [oz]                <Unit>                  (4.0) <Unit of mass> Ounce (kg=1)
  376. [lb]                <Unit>                  (4.0) <Unit of mass> Pound (kg=1)
  377. [b]                 <Unit>                  (4.0) <Unit of information> Bit (bit=1)
  378. [kb]                <Unit>                  (4.0) <Unit of information> Kilobit (bit=1)
  379. [Mb]                <Unit>                  (4.0) <Unit of information> Megabit (bit=1)
  380. [Gb]                <Unit>                  (4.0) <Unit of information> Gigabit (bit=1)
  381. [Tb]                <Unit>                  (4.0) <Unit of information> Terabit (bit=1)
  382. [Pb]                <Unit>                  (4.0) <Unit of information> Petabit (bit=1)
  383. [Eb]                <Unit>                  (4.0) <Unit of information> Exabit (bit=1)
  384. [Zb]                <Unit>                  (4.0) <Unit of information> Zettabit (bit=1)
  385. [Yb]                <Unit>                  (4.0) <Unit of information> Yottabit (bit=1)
  386. [B]                 <Unit>                  (4.0) <Unit of information> Byte (bit=1)
  387. [kB]                <Unit>                  (4.0) <Unit of information> Kilobyte (bit=1)
  388. [MB]                <Unit>                  (4.0) <Unit of information> Megabyte (bit=1)
  389. [GB]                <Unit>                  (4.0) <Unit of information> Gigabyte (bit=1)
  390. [TB]                <Unit>                  (4.0) <Unit of information> Terabyte (bit=1)
  391. [PB]                <Unit>                  (4.0) <Unit of information> Petabyte (bit=1)
  392. [EB]                <Unit>                  (4.0) <Unit of information> Exabyte (bit=1)
  393. [ZB]                <Unit>                  (4.0) <Unit of information> Zettabyte (bit=1)
  394. [YB]                <Unit>                  (4.0) <Unit of information> Yottabyte (bit=1)
  395. [J]                 <Unit>                  (4.0) <Unit of energy> Joule (m=1, kg=1, s=1)
  396. [eV]                <Unit>                  (4.0) <Unit of energy> Electronovolt (m=1, kg=1, s=1)
  397. [keV]               <Unit>                  (4.0) <Unit of energy> Kiloelectronovolt (m=1, kg=1, s=1)
  398. [MeV]               <Unit>                  (4.0) <Unit of energy> Megaelectronovolt (m=1, kg=1, s=1)
  399. [GeV]               <Unit>                  (4.0) <Unit of energy> Gigaelectronovolt (m=1, kg=1, s=1)
  400. [TeV]               <Unit>                  (4.0) <Unit of energy> Teraelectronovolt (m=1, kg=1, s=1)
  401. [m/s]               <Unit>                  (4.0) <Unit of speed> Metre / Meter per second (m=1, s=1)
  402. [km/h]              <Unit>                  (4.0) <Unit of speed> Kilometre / Kilometer per hour (m=1, s=1)
  403. [mi/h]              <Unit>                  (4.0) <Unit of speed> Mile per hour (m=1, s=1)
  404. [knot]              <Unit>                  (4.0) <Unit of speed> Knot (m=1, s=1)
  405. [m/s2]              <Unit>                  (4.0) <Unit of acceleration> Metre / Meter per square second (m=1, s=1)
  406. [km/h2]             <Unit>                  (4.0) <Unit of acceleration> Kilometre / Kilometer per square hour (m=1, s=1)
  407. [mi/h2]             <Unit>                  (4.0) <Unit of acceleration> Mile per square hour (m=1, s=1)
  408. [rad]               <Unit>                  (4.0) <Unit of angle> Radian (rad=1)
  409. [deg]               <Unit>                  (4.0) <Unit of angle> Degree of arc (rad=1)
  410. [']                 <Unit>                  (4.0) <Unit of angle> Minute of arc (rad=1)
  411. ['']                <Unit>                  (4.0) <Unit of angle> Second of arc (rad=1)

*** If you found the software useful donation is something you might consider 🙂 ***

If you found the software useful donation is something you might consider :-)

Enjoy! 🙂

 

Best regards,

Mariusz Gromada

Download latest release – v.4.0.0.2: bin + doc + src (.zip 10.7 MB)

Download latest release – v.4.0.0.2: bin only (.zip 3.04 MB) – separate binaries for java: 1.5, 1.6, 1.7, 1.8; .NET: 2.0, 3.0, 3.5, 4.0, 4.5, 4.6, .NET Core, .NET Standard, .NET PCL, Xamarin.Android, Xamarin.iOS

Source code .zipSource code .tar.gz View on GitHubMathSpace.pl