Giter Site home page Giter Site logo

fraction-ts's Introduction

Fraction Library

Overview

This TypeScript library provides a robust solution for managing fractions, enabling their creation, manipulation, and conversion with ease. It is designed to handle both simple and complex fraction operations.

Features

  • Fraction Creation: Create fractions from strings or numerical inputs.
  • Advanced Operations: Perform arithmetic operations with fractions.
  • Conversion: Convert fractions to decimals, including handling of repeating decimals.

Types

RepeatingDecimal

A type representing a decimal number that may have repeating digits. It consists of:

  • integer: The integer part of the decimal.
  • nonRepeating: The non-repeating part of the decimal, if any.
  • repeating: The repeating part of the decimal, if any.

Classes

Fraction

A class that represents a fraction. It supports operations such as addition, subtraction, multiplication, and division.

Constructors

  • constructor(fractionString: string): Create a fraction from a string representation.
    • like "1/2","1.23(456)"
    • If invalid string is passed, top and bottom are set to NaN
  • constructor(top: number, bottom: number): Create a fraction using numerator and denominator.
    • If 0 is passed as bottom, top and bottom are set to NaN

Basic Usage

// Example of creating a fraction from a string
const fractionFromString = new Fraction("1/2");

// Example of creating a fraction with numerator and denominator
const fractionFromNumbers = new Fraction(1, 2);

// Example of creating a fraction from a repeating decimal
const fractionFromRepeatingDecimal = new Fraction("0.5");

License

MIT

fraction-ts's People

Contributors

aurora1530 avatar

Watchers

 avatar

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.