Giter VIP home page Giter VIP logo

calculator's Introduction

React Calculator

A calculator project built with React.

Calculator Screenshot

Features

  1. Add, subtract, multiply, divide
  2. Support decimal values
  3. Calculate percentages
  4. Invert the values
  5. Reset functionality
  6. Format larger numbers
  7. Output resize based on length

Installation

  1. git clone https://github.com/madzadev/calculator.git

  2. cd calculator

  3. npm install

  4. npm start

Contributions

Any feature requests and pull requests are welcome!

License

The project is under MIT license.

calculator's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

calculator's Issues

Floating point issue with percent button

Entering a decimal such as 5.4 and then clicking the % button introduces floating point errors.

Two possible solutions:

  • Multiply by big powers of 10:
const bigPercent = (num) => (num * 10**16 / 10**18).toString()
  • Move decimal left two places in array version of number:
function moveDecimalLeft (number, places) {
  if (places < 0) {
    console.log("'places' parameter must be >= 0")
  return
  }
  const zeros = Array(places).fill("0");
  let numArr = [...zeros, ...number.toString().split("")];
  let idx = numArr.indexOf(".")
  idx < 0
    ? numArr.splice(numArr.length - places, 0, ".")
    : numArr.splice(idx - places, 0, numArr.splice(idx, 1))
  return parseFloat(numArr.join("")).toString()
}

Pull request

Hi, thanks for building this, it's great. I have a small pull request to improve handling zero division. Could I be added as a contributor so I can push the branch?

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.