Fractions

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

Tutorial Math Collection API spec Download

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

Case 1: Fraction (proper) as Number Literal

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("1_2");
mXparser.consolePrintln(e.getExpressionString() + " = " + e.calculate());
[mXparser-v.5.0.3] 1_2 = 0.5

Case 2: Improper Fraction as Number Literal

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("-6_5");
mXparser.consolePrintln(e.getExpressionString() + " = " + e.calculate());
[mXparser-v.5.0.3] -6_5 = -1.2

Case 3: Fraction (Mixed Number) as Number Literal

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("2_3_5");
mXparser.consolePrintln(e.getExpressionString() + " = " + e.calculate());
[mXparser-v.5.0.3] 2_3_5 = 2.6

Case 4: Fraction (Mixed Numer) and Improper Fraction in one Number Literal

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("2_12_5");
mXparser.consolePrintln(e.getExpressionString() + " = " + e.calculate());
[mXparser-v.5.0.3] 2_12_5 = 4.4

Case 5: Operations on Fractions

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("1_2-6_5*2_3_5/2_12_5");
mXparser.consolePrintln(e.getExpressionString() + " = " + e.calculate());
[mXparser-v.5.0.3] 1_2-6_5*2_3_5/2_12_5 = -0.2090909090909091

Case 6: Represent double as Fraction

import org.mariuszgromada.math.mxparser.*;
...
Expression e = new Expression("1_2-6_5*2_3_5/2_12_5");
double resultAsDouble = e.calculate();
String resultAsFraction = mXparser.toFractionString(resultAsDouble);
mXparser.consolePrintln(e.getExpressionString() + " = " + resultAsFraction);
[mXparser-v.5.0.3] 1_2-6_5*2_3_5/2_12_5 = -23/110
Nuget – Package Manager

Install-Package MathParser.org-mXparser -Version 5.0.6

Nuget – .NET CLI

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

Nuget – Package Reference

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

Maven – Dependency

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

Maven – Gradle

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

Maven – Gradle (Kotlin)

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

GitHub

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

OTHER DOWNLOAD OPTIONS

Download latest release – v.5.0.6 Leonis: .NET bin onlyDownload latest release – v.5.0.6 Leonis: JAVA bin onlyDownload latest release – v.5.0.6 Leonis: 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