Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fix-a-float

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fix-a-float

Remove precision nightmares from numbers.

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Fix-A-Float

Ever had this problem?

>> 0.1 + 0.2
0.30000000000000004

This solves that problem.

>> fixAfloat(0.1 + 0.2)
0.3

Installation

npm install fix-a-float

Usage

var fixAfloat = require('fix-a-float');

console.log(fixAfloat(0.1+0.2));

How does it do it?

It converts the number to a string, looks for a long run of zeros or nines at the end, removes them, and coverts back to a float.

Should I use this all the time, everywhere?

Absolutely not. Only use it in places where you need human readable numbers but don't know the precision you need. It doesn't actually solve any of the larger issues with floats.

Keywords

FAQs

Package last updated on 28 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc