Built-in Units

TO SUPPORT MY WORK, ORDER A COMMERCIAL LICENSE
THANK YOU!

The tutorial consists of more than 200 live examples from 50 sections. Each of the examples can be copied and run on your own environment. In addition, mXparser provides an extensive collection of over 500 built-in math functions, expressions and symbols. Familiarize yourself with the scope and the syntax. Live testing is the best way to learn. Good luck! 🙂

Tutorial Math Collection API spec Download

Below is the code for JAVA, the code for C# is almost identical.

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.5.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.5.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.5.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.5.0.0] Res: 2000*[l] / [m3] = 2.0

Case 5: Express 4 feet in inches

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("4[ft]/[inch]");
mXparser.consolePrintln(e.getExpressionString() + " = " + e.calculate());
[mXparser-v.5.0.2] 4[ft]/[inch] = 48.0

Case 6: Express in square kilometers the area of a rectangle measuring 100 meters by 2 kilometers

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("100[m] * 2[km] / [km2]");
mXparser.consolePrintln(e.getExpressionString() + " = " + e.calculate());
[mXparser-v.5.0.2] 100[m] * 2[km] / [km2] = 0.2

Case 7: List of supported units

import org.mariuszgromada.math.mxparser.*;
...
mXparser.consolePrintHelp("<unit>");
Help content: 

    #  key word            type                    syntax                                        since description
    -  --------            ----                    ------                                        ----- -----------
  409. [%]                 <Unit>                  [%]                                           4.0   <Ratio, Fraction> Percentage = 0.01
  410. [%%]                <Unit>                  [%%]                                          4.0   <Ratio, Fraction> Promil, Per mille = 0.001
  411. [Y]                 <Unit>                  [Y]                                           4.0   <Metric prefix> Septillion / Yotta = 10^24
  412. [sept]              <Unit>                  [sept]                                        4.0   <Metric prefix> Septillion / Yotta = 10^24
  413. [Z]                 <Unit>                  [Z]                                           4.0   <Metric prefix> Sextillion / Zetta = 10^21
  414. [sext]              <Unit>                  [sext]                                        4.0   <Metric prefix> Sextillion / Zetta = 10^21
  415. [E]                 <Unit>                  [E]                                           4.0   <Metric prefix> Quintillion / Exa = 10^18
  416. [quint]             <Unit>                  [quint]                                       4.0   <Metric prefix> Quintillion / Exa = 10^18
  417. [P]                 <Unit>                  [P]                                           4.0   <Metric prefix> Quadrillion / Peta = 10^15
  418. [quad]              <Unit>                  [quad]                                        4.0   <Metric prefix> Quadrillion / Peta = 10^15
  419. [T]                 <Unit>                  [T]                                           4.0   <Metric prefix> Trillion / Tera = 10^12
  420. [tril]              <Unit>                  [tril]                                        4.0   <Metric prefix> Trillion / Tera = 10^12
  421. [G]                 <Unit>                  [G]                                           4.0   <Metric prefix> Billion / Giga = 10^9
  422. [bil]               <Unit>                  [bil]                                         4.0   <Metric prefix> Billion / Giga = 10^9
  423. [M]                 <Unit>                  [M]                                           4.0   <Metric prefix> Million / Mega = 10^6
  424. [mil]               <Unit>                  [mil]                                         4.0   <Metric prefix> Million / Mega = 10^6
  425. [k]                 <Unit>                  [k]                                           4.0   <Metric prefix> Thousand / Kilo = 10^3
  426. [th]                <Unit>                  [th]                                          4.0   <Metric prefix> Thousand / Kilo = 10^3
  427. [hund]              <Unit>                  [hund]                                        4.0   <Metric prefix> Hundred / Hecto = 10^2
  428. [hecto]             <Unit>                  [hecto]                                       4.0   <Metric prefix> Hundred / Hecto = 10^2
  429. [ten]               <Unit>                  [ten]                                         4.0   <Metric prefix> Ten / Deca = 10
  430. [deca]              <Unit>                  [deca]                                        4.0   <Metric prefix> Ten / Deca = 10
  431. [deci]              <Unit>                  [deci]                                        4.0   <Metric prefix> Tenth / Deci = 0.1
  432. [centi]             <Unit>                  [centi]                                       4.0   <Metric prefix> Hundredth / Centi = 0.01
  433. [milli]             <Unit>                  [milli]                                       4.0   <Metric prefix> Thousandth / Milli = 0.001
  434. [mic]               <Unit>                  [mic]                                         4.0   <Metric prefix> Millionth / Micro = 10^-6
  435. [n]                 <Unit>                  [n]                                           4.0   <Metric prefix> Billionth / Nano = 10^-9
  436. [p]                 <Unit>                  [p]                                           4.0   <Metric prefix> Trillionth / Pico = 10^-12
  437. [f]                 <Unit>                  [f]                                           4.0   <Metric prefix> Quadrillionth / Femto = 10^-15
  438. [a]                 <Unit>                  [a]                                           4.0   <Metric prefix> Quintillionth / Atoo = 10^-18
  439. [z]                 <Unit>                  [z]                                           4.0   <Metric prefix> Sextillionth / Zepto = 10^-21
  440. [y]                 <Unit>                  [y]                                           4.0   <Metric prefix> Septillionth / Yocto = 10^-24
  441. [m]                 <Unit>                  [m]                                           4.0   <Unit of length> Metre / Meter (m=1)
  442. [km]                <Unit>                  [km]                                          4.0   <Unit of length> Kilometre / Kilometer (m=1)
  443. [cm]                <Unit>                  [cm]                                          4.0   <Unit of length> Centimetre / Centimeter (m=1)
  444. [mm]                <Unit>                  [mm]                                          4.0   <Unit of length> Millimetre / Millimeter (m=1)
  445. [inch]              <Unit>                  [inch]                                        4.0   <Unit of length> Inch (m=1)
  446. [yd]                <Unit>                  [yd]                                          4.0   <Unit of length> Yard (m=1)
  447. [ft]                <Unit>                  [ft]                                          4.0   <Unit of length> Feet (m=1)
  448. [mile]              <Unit>                  [mile]                                        4.0   <Unit of length> Mile (m=1)
  449. [nmi]               <Unit>                  [nmi]                                         4.0   <Unit of length> Nautical mile (m=1)
  450. [m2]                <Unit>                  [m2]                                          4.0   <Unit of area> Square metre / Square meter (m=1)
  451. [cm2]               <Unit>                  [cm2]                                         4.0   <Unit of area> Square centimetre / Square centimeter (m=1)
  452. [mm2]               <Unit>                  [mm2]                                         4.0   <Unit of area> Square millimetre / Square millimeter (m=1)
  453. [are]               <Unit>                  [are]                                         4.0   <Unit of area> Are (m=1)
  454. [ha]                <Unit>                  [ha]                                          4.0   <Unit of area> Hectare (m=1)
  455. [acre]              <Unit>                  [acre]                                        4.0   <Unit of area> Acre (m=1)
  456. [km2]               <Unit>                  [km2]                                         4.0   <Unit of area> Square kilometre / Square kilometer (m=1)
  457. [mm3]               <Unit>                  [mm3]                                         4.0   <Unit of volume> Cubic millimetre / Cubic millimeter (m=1)
  458. [cm3]               <Unit>                  [cm3]                                         4.0   <Unit of volume> Cubic centimetre / Cubic centimeter (m=1)
  459. [m3]                <Unit>                  [m3]                                          4.0   <Unit of volume> Cubic metre / Cubic meter (m=1)
  460. [km3]               <Unit>                  [km3]                                         4.0   <Unit of volume> Cubic kilometre / Cubic kilometer (m=1)
  461. [ml]                <Unit>                  [ml]                                          4.0   <Unit of volume> Millilitre / Milliliter (m=1)
  462. [l]                 <Unit>                  [l]                                           4.0   <Unit of volume> Litre / Liter (m=1)
  463. [gall]              <Unit>                  [gall]                                        4.0   <Unit of volume> Gallon (m=1)
  464. [pint]              <Unit>                  [pint]                                        4.0   <Unit of volume> Pint (m=1)
  465. [s]                 <Unit>                  [s]                                           4.0   <Unit of time> Second (s=1)
  466. [ms]                <Unit>                  [ms]                                          4.0   <Unit of time> Millisecond (s=1)
  467. [min]               <Unit>                  [min]                                         4.0   <Unit of time> Minute (s=1)
  468. [h]                 <Unit>                  [h]                                           4.0   <Unit of time> Hour (s=1)
  469. [day]               <Unit>                  [day]                                         4.0   <Unit of time> Day (s=1)
  470. [week]              <Unit>                  [week]                                        4.0   <Unit of time> Week (s=1)
  471. [yearj]             <Unit>                  [yearj]                                       4.0   <Unit of time> Julian year = 365.25 days (s=1)
  472. [kg]                <Unit>                  [kg]                                          4.0   <Unit of mass> Kilogram (kg=1)
  473. [gr]                <Unit>                  [gr]                                          4.0   <Unit of mass> Gram (kg=1)
  474. [mg]                <Unit>                  [mg]                                          4.0   <Unit of mass> Milligram (kg=1)
  475. [dag]               <Unit>                  [dag]                                         4.0   <Unit of mass> Decagram (kg=1)
  476. [t]                 <Unit>                  [t]                                           4.0   <Unit of mass> Tonne (kg=1)
  477. [oz]                <Unit>                  [oz]                                          4.0   <Unit of mass> Ounce (kg=1)
  478. [lb]                <Unit>                  [lb]                                          4.0   <Unit of mass> Pound (kg=1)
  479. [b]                 <Unit>                  [b]                                           4.0   <Unit of information> Bit (bit=1)
  480. [kb]                <Unit>                  [kb]                                          4.0   <Unit of information> Kilobit (bit=1)
  481. [Mb]                <Unit>                  [Mb]                                          4.0   <Unit of information> Megabit (bit=1)
  482. [Gb]                <Unit>                  [Gb]                                          4.0   <Unit of information> Gigabit (bit=1)
  483. [Tb]                <Unit>                  [Tb]                                          4.0   <Unit of information> Terabit (bit=1)
  484. [Pb]                <Unit>                  [Pb]                                          4.0   <Unit of information> Petabit (bit=1)
  485. [Eb]                <Unit>                  [Eb]                                          4.0   <Unit of information> Exabit (bit=1)
  486. [Zb]                <Unit>                  [Zb]                                          4.0   <Unit of information> Zettabit (bit=1)
  487. [Yb]                <Unit>                  [Yb]                                          4.0   <Unit of information> Yottabit (bit=1)
  488. [B]                 <Unit>                  [B]                                           4.0   <Unit of information> Byte (bit=1)
  489. [kB]                <Unit>                  [kB]                                          4.0   <Unit of information> Kilobyte (bit=1)
  490. [MB]                <Unit>                  [MB]                                          4.0   <Unit of information> Megabyte (bit=1)
  491. [GB]                <Unit>                  [GB]                                          4.0   <Unit of information> Gigabyte (bit=1)
  492. [TB]                <Unit>                  [TB]                                          4.0   <Unit of information> Terabyte (bit=1)
  493. [PB]                <Unit>                  [PB]                                          4.0   <Unit of information> Petabyte (bit=1)
  494. [EB]                <Unit>                  [EB]                                          4.0   <Unit of information> Exabyte (bit=1)
  495. [ZB]                <Unit>                  [ZB]                                          4.0   <Unit of information> Zettabyte (bit=1)
  496. [YB]                <Unit>                  [YB]                                          4.0   <Unit of information> Yottabyte (bit=1)
  497. [J]                 <Unit>                  [J]                                           4.0   <Unit of energy> Joule (m=1, kg=1, s=1)
  498. [eV]                <Unit>                  [eV]                                          4.0   <Unit of energy> Electronovolt (m=1, kg=1, s=1)
  499. [keV]               <Unit>                  [keV]                                         4.0   <Unit of energy> Kiloelectronovolt (m=1, kg=1, s=1)
  500. [MeV]               <Unit>                  [MeV]                                         4.0   <Unit of energy> Megaelectronovolt (m=1, kg=1, s=1)
  501. [GeV]               <Unit>                  [GeV]                                         4.0   <Unit of energy> Gigaelectronovolt (m=1, kg=1, s=1)
  502. [TeV]               <Unit>                  [TeV]                                         4.0   <Unit of energy> Teraelectronovolt (m=1, kg=1, s=1)
  503. [m/s]               <Unit>                  [m/s]                                         4.0   <Unit of speed> Metre / Meter per second (m=1, s=1)
  504. [km/h]              <Unit>                  [km/h]                                        4.0   <Unit of speed> Kilometre / Kilometer per hour (m=1, s=1)
  505. [mi/h]              <Unit>                  [mi/h]                                        4.0   <Unit of speed> Mile per hour (m=1, s=1)
  506. [knot]              <Unit>                  [knot]                                        4.0   <Unit of speed> Knot (m=1, s=1)
  507. [m/s2]              <Unit>                  [m/s2]                                        4.0   <Unit of acceleration> Metre / Meter per square second (m=1, s=1)
  508. [km/h2]             <Unit>                  [km/h2]                                       4.0   <Unit of acceleration> Kilometre / Kilometer per square hour (m=1, s=1)
  509. [mi/h2]             <Unit>                  [mi/h2]                                       4.0   <Unit of acceleration> Mile per square hour (m=1, s=1)
  510. [rad]               <Unit>                  [rad]                                         4.0   <Unit of angle> Radian (rad=1)
  511. [deg]               <Unit>                  [deg]                                         4.0   <Unit of angle> Degree of arc (rad=1)
  512. [']                 <Unit>                  [']                                           4.0   <Unit of angle> Minute of arc (rad=1)
  513. ['']                <Unit>                  ['']                                          4.0   <Unit of angle> Second of arc (rad=1)
Nuget – Package Manager

Install-Package MathParser.org-mXparser -Version 5.2.0

Nuget – .NET CLI

dotnet add package MathParser.org-mXparser --version 5.2.0

Nuget – Package Reference

<PackageReference Include="MathParser.org-mXparser" Version="5.2.0"/>

Maven – Dependency

<dependency>
<groupid>
org.mariuszgromada.math</groupid>
<artifactid>
MathParser.org-mXparser</artifactid>
<version>
5.2.0</version>
</dependency>

Maven – Gradle

implementation 'org.mariuszgromada.math:MathParser.org-mXparser:5.2.0'

Maven – Gradle (Kotlin)

implementation("org.mariuszgromada.math:MathParser.org-mXparser:5.2.0")

GitHub

git clone https://github.com/mariuszgromada/MathParser.org-mXparser

OTHER DOWNLOAD OPTIONS

Download latest release – v.5.2.0 Orion: .NET bin onlyDownload latest release – v.5.2.0 Orion: JAVA bin onlyDownload latest release – v.5.2.0 Orion: bin + doc

NEWS FROM MATHPARSER.ORG
SOURCE CODE

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

DONATION
Did you find the software useful?
Please consider donation 🙂
DONATE