Git Product home page Git Product logo

wgaffa-numbers-fraction's Introduction

GitHub Nuget

Fractions

Fractions is a basic library to be able to calculate and represent fractions. All fractions are in its simples form.

Installation

Install-Package Wgaffa.Numbers.Fraction

Using fractions

Everything resides in the namespace Wgaffa.Numbers, so use this when you wish to use this library.

using Wgaffa.Numbers;

Create some simple fractions.

var aFourth = new Fraction(1, 4); // 1/4
var oneAndEights = new Fraction(9, 8); // 1 1/8
var negativeFraction = new Fraction(-2, 3); // -2/3
var simplestForm = new Fraction(5, 10); // 1/2

To create mixed fractions with addition operator.

var mixedFraction = new Fraction(1, 4) + 5; // 5 1/4

ToString() will return a mixed fraction, e.g.

var mixedFraction = new Fraction(5, 2);
Console.WriteLine(mixedFraction); // Output: 2 1/2

If you want to print out the improper fraction you have to use the properties Numerator and Denominator.

var mixedFraction = new Fraction(8, 3);
Console.WriteLine($"{mixedFraction.Numerator}/{mixedFraction.Denominator}"); // Output: 8/3

Using the previous examples you can use the operators + - * / on fractions and integers.

var addition = aFourth + simplestForm; // 3/4
var subtraction = oneAndEights - aFourth; // 7/8
var multiplication = negativeFraction * aFourth; // -1/6
var division = simplestForm / aFourth; // 2

wgaffa-numbers-fraction's People

Contributors

wgaffa avatar

Stargazers

mars2nico avatar

Watchers

 avatar James Cloos avatar

wgaffa-numbers-fraction's Issues

Add operators

I think we should overload some comparison operators

This will be in line with all other libraries in the namespace

Create Readme

Create a small Readme file on how to use this class

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.