Fractional.NET
1.0.0
This is simple .NET Core library for parsing and working with fractinal expressions.
Install-Package Fractional.NET -Version 1.0.0
dotnet add package Fractional.NET --version 1.0.0
<PackageReference Include="Fractional.NET" Version="1.0.0" />
paket add Fractional.NET --version 1.0.0
Conversion
Basic conversion operations
Conversion to human readable fraction
Conversion of decimals with approximate guessing :
var f1 = new Fractional(0.333333d, keepExcat: false);
var f2 = new Fractional(0.75d, keepExcat: false);
Console.WriteLine(f1.HumanRepresentation); // Output: 1/3
Console.WriteLine(f2.HumanRepresentation); // Output: 3/4
Conversion of decimals without approximate guessing :
var f1 = new Fractional(0.333333d, keepExcat: true);
var f2 = new Fractional(0.75d, keepExcat: true);
Console.WriteLine(f1); // Output: 333333/1000000
Console.WriteLine(f2); // Output: 75/100
Conversion to decimal
Conversion to human fractions to decimals
var f1 = new Fractional("7 3/4");
var f2 = new Fractional("3/4");
Console.WriteLine(f1.Value); // Output: 7.75
Console.WriteLine(f2.Value); // Output: 0.75
Arithmetic operations and Comparisons
The fraction instance work very well with math operators even with other numerics and string representations :
var f1 = new Fractional("3/4");
var f2 = new Fractional("1/2");
Console.WriteLine(f1 + 0.5d); // Output: 1 1/4
Console.WriteLine(f1 + f2); // Output: 1 1/4
Console.WriteLine(f1 - 1.75d); // Output: -1
Console.WriteLine(f1 - f2); // Output: 1/4
It does the same work with Comparisons operators
var f1 = new Fractional("5 3/2");
var f2 = new Fractional("3 3/2");
Console.WriteLine(f1 > f2); // Output: true
Console.WriteLine(f1 < 7.0d); // Output: true
Console.WriteLine(f2 > 5.0d); // Output: false
Conversion
Basic conversion operations
Conversion to human readable fraction
Conversion of decimals with approximate guessing :
var f1 = new Fractional(0.333333d, keepExcat: false);
var f2 = new Fractional(0.75d, keepExcat: false);
Console.WriteLine(f1.HumanRepresentation); // Output: 1/3
Console.WriteLine(f2.HumanRepresentation); // Output: 3/4
Conversion of decimals without approximate guessing :
var f1 = new Fractional(0.333333d, keepExcat: true);
var f2 = new Fractional(0.75d, keepExcat: true);
Console.WriteLine(f1); // Output: 333333/1000000
Console.WriteLine(f2); // Output: 75/100
Conversion to decimal
Conversion to human fractions to decimals
var f1 = new Fractional("7 3/4");
var f2 = new Fractional("3/4");
Console.WriteLine(f1.Value); // Output: 7.75
Console.WriteLine(f2.Value); // Output: 0.75
Arithmetic operations and Comparisons
The fraction instance work very well with math operators even with other numerics and string representations :
var f1 = new Fractional("3/4");
var f2 = new Fractional("1/2");
Console.WriteLine(f1 + 0.5d); // Output: 1 1/4
Console.WriteLine(f1 + f2); // Output: 1 1/4
Console.WriteLine(f1 - 1.75d); // Output: -1
Console.WriteLine(f1 - f2); // Output: 1/4
It does the same work with Comparisons operators
var f1 = new Fractional("5 3/2");
var f2 = new Fractional("3 3/2");
Console.WriteLine(f1 > f2); // Output: true
Console.WriteLine(f1 < 7.0d); // Output: true
Console.WriteLine(f2 > 5.0d); // Output: false
Dependencies
-
.NETStandard 2.0
- No dependencies.
Used By
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version History
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 392 | 1/6/2019 |
1.0.0-beta | 342 | 12/26/2018 |