<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/why-javascript-floating-point-math-breaks-your-app-and-how-to-fix-it--0nl3mfyyi" -->

---
title: Why JavaScript Floating Point Math Breaks Your App (And...
description: JavaScript uses IEEE 754 double-precision floating point for all numbers, meaning decimals like 0.1 + 0.2 can't be represented exactly in binary. This causes...
canonical: https://daily.dev/posts/why-javascript-floating-point-math-breaks-your-app-and-how-to-fix-it--0nl3mfyyi
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Why JavaScript Floating Point Math Breaks Your App (And How to Fix It) | daily.dev
og:description: JavaScript uses IEEE 754 double-precision floating point for all numbers, meaning decimals like 0.1 + 0.2 can't be represented exactly in binary. This causes...
og:url: https://daily.dev/posts/why-javascript-floating-point-math-breaks-your-app-and-how-to-fix-it--0nl3mfyyi
og:image: https://api.daily.dev/og/posts/0nl3MfYYI.png
og:image:alt: Why JavaScript Floating Point Math Breaks Your App (And How to Fix It)
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Why JavaScript Floating Point Math Breaks Your App (And How to Fix It)

**[Sergio Lema](https://daily.dev/sources/sergiolema-dev)** · 5 min read · 1 upvotes · 0 comments

## Summary

JavaScript uses IEEE 754 double-precision floating point for all numbers, meaning decimals like 0.1 + 0.2 can't be represented exactly in binary. This causes subtle bugs in financial and precision-sensitive code — not just the obvious 0.1 + 0.2 case, but composed calculations like Math.ceil(1.7000000000000002 * 100) / 100 producing 1.71 instead of 1.70. Four practical solutions are covered: using toFixed() only for display output, working in integer cents for monetary values, a scale-round-ceil pattern to neutralize floating point noise in pre-computed floats, and using decimal.js or big.js for complex chained financial calculations. The recommended default for money is integer arithmetic.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://sergiolema.dev/2026/04/06/why-javascript-floating-point-math-breaks-your-app-and-how-to-fix-it/>

## Similar posts on daily.dev

- [Mathematical precision in Javascript](https://daily.dev/posts/mathematical-precision-in-javascript-zwkniwuun) · Chen Hui Jing · 0 upvotes · 0 comments
- [How to Understand the Safe Integer Limit in JavaScript](https://daily.dev/posts/how-to-understand-the-safe-integer-limit-in-javascript-4vq0h3lnj) · freeCodeCamp · 5 upvotes · 2 comments
- [Why You Should Never Use Floating Point for Money](https://daily.dev/posts/why-you-should-never-use-floating-point-for-money-mf4k3pznd) · Sergio Lema · 17 upvotes · 6 comments
- [Why Ruby’s Issue Tracker Still Links to a 1991 Paper About Floating-Point Numbers](https://daily.dev/posts/why-ruby-s-issue-tracker-still-links-to-a-1991-paper-about-floating-point-numbers-vijgzx189) · RUBYLAND · 1 upvotes · 1 comments

---

Tags: [#general-programming](https://daily.dev/tags/general-programming), [#javascript](https://daily.dev/tags/javascript)

[View this post on daily.dev](https://daily.dev/posts/why-javascript-floating-point-math-breaks-your-app-and-how-to-fix-it--0nl3mfyyi)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Why JavaScript Floating Point Math Breaks Your App (And How to Fix It)","url":"https://daily.dev/posts/why-javascript-floating-point-math-breaks-your-app-and-how-to-fix-it--0nl3mfyyi","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/why-javascript-floating-point-math-breaks-your-app-and-how-to-fix-it--0nl3mfyyi"},"datePublished":"2026-04-06T05:04:33.302Z","dateModified":"2026-10-15T02:22:18.463Z","description":"JavaScript uses IEEE 754 double-precision floating point for all numbers, meaning decimals like 0.1 + 0.2 can't be represented exactly in binary. This causes...","image":"https://i0.wp.com/sergiolema.dev/wp-content/uploads/2026/03/pexels-photo-30488931.jpeg?fit=1200%2C795&ssl=1","thumbnailUrl":"https://i0.wp.com/sergiolema.dev/wp-content/uploads/2026/03/pexels-photo-30488931.jpeg?fit=1200%2C795&ssl=1","isAccessibleForFree":true,"articleSection":"Sergio Lema","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Sergio Lema","logo":"https://media.daily.dev/image/upload/s--SxVeO2EZ--/f_auto,q_auto/v1774964060/logos/sergiolema-dev?_a=BAMAMiWQ0","url":"https://daily.dev/sources/sergiolema-dev"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/why-javascript-floating-point-math-breaks-your-app-and-how-to-fix-it--0nl3mfyyi","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"general-programming,javascript","timeRequired":"PT5M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Sergio Lema","item":"https://daily.dev/sources/sergiolema-dev"},{"@type":"ListItem","position":3,"name":"Why JavaScript Floating Point Math Breaks Your App (And How to Fix It)"}]}
```

