<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-to-fix-decimals-arithmetic-in-javascript-2kkv-zr0n" -->

---
title: How to fix decimals arithmetic in JavaScript | daily.dev
description: If you try to do the sum of two decimal numbers in JavaScript you might have a surprise. The reason is due to the fact computers store data as binary, 0 or 1....
canonical: https://daily.dev/posts/how-to-fix-decimals-arithmetic-in-javascript-2kkv-zr0n
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How to fix decimals arithmetic in JavaScript | daily.dev
og:description: If you try to do the sum of two decimal numbers in JavaScript you might have a surprise. The reason is due to the fact computers store data as binary, 0 or 1....
og:url: https://daily.dev/posts/how-to-fix-decimals-arithmetic-in-javascript-2kkv-zr0n
og:image: https://api.daily.dev/og/posts/2KkV_zR0n.png
og:image:alt: How to fix decimals arithmetic in JavaScript
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.

# How to fix decimals arithmetic in JavaScript

**[Flavio Copes](https://daily.dev/sources/flaviocopes)** · 2 min read · 10 upvotes · 1 comments

## Summary

If you try to do the sum of two decimal numbers in JavaScript you might have a surprise. The reason is due to the fact computers store data as binary, 0 or 1. Not every decimal number can be represented perfectly in this binary format. Some numbers are repeating numbers in binary. Try to convert 0.1 from decimal to binary.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://flaviocopes.com/javascript-decimal-arithmetics/>

## Community discussion

Top comments from developers on daily.dev.

**@\_fotinovski16925728762628446434127172** · 0 upvotes

> Thanks, Flavio!
> This one helped me a lot 🙌

## Similar posts on daily.dev

- [Don’t just attend KubeCon \+ CloudNativeCon, Merge Forward your experience\!](https://daily.dev/posts/don-t-just-attend-kubecon-cloudnativecon-merge-forward-your-experience--l0rpp73x8) · CNCF · 1 upvotes · 0 comments
- [Announcing H2 2026 KCDs](https://daily.dev/posts/announcing-h2-2026-kcds-m96goajm1) · CNCF · 1 upvotes · 0 comments
- [Two months of Open Community Groups](https://daily.dev/posts/two-months-of-open-community-groups-asf52zhbs) · CNCF · 0 upvotes · 0 comments

---

Tags: [#javascript](https://daily.dev/tags/javascript)

[View this post on daily.dev](https://daily.dev/posts/how-to-fix-decimals-arithmetic-in-javascript-2kkv-zr0n)

```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":"How to fix decimals arithmetic in JavaScript","url":"https://daily.dev/posts/how-to-fix-decimals-arithmetic-in-javascript-2kkv-zr0n","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-to-fix-decimals-arithmetic-in-javascript-2kkv-zr0n"},"datePublished":"2022-04-25T06:11:40.185Z","dateModified":"2022-04-25T06:11:40.185Z","description":"If you try to do the sum of two decimal numbers in JavaScript you might have a surprise. The reason is due to the fact computers store data as binary, 0 or 1....","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/cc95d926daee34703c50c720048555da","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/cc95d926daee34703c50c720048555da","isAccessibleForFree":true,"articleSection":"Flavio Copes","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":"Flavio Copes","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/1f2dbd275797411bbd37bfdaaf0951a9","url":"https://daily.dev/sources/flaviocopes"},"commentCount":1,"discussionUrl":"https://daily.dev/posts/how-to-fix-decimals-arithmetic-in-javascript-2kkv-zr0n","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":10},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":1}],"keywords":"javascript","timeRequired":"PT2M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Flavio Copes","item":"https://daily.dev/sources/flaviocopes"},{"@type":"ListItem","position":3,"name":"How to fix decimals arithmetic in JavaScript"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/how-to-fix-decimals-arithmetic-in-javascript-2kkv-zr0n","comment":[{"@type":"Comment","text":"Thanks, Flavio!\nThis one helped me a lot 🙌","datePublished":"2022-04-26T07:48:34.355Z","url":"https://daily.dev/posts/2KkV_zR0n#c-sCyOKMt4v","author":{"@type":"Person","name":"Darko Fotinovski","url":"https://daily.dev/_fotinovski16925728762628446434127172","image":"https://lh3.googleusercontent.com/a/AATXAJxnnpNBXNL9D49SV-P7ckewKXyaL8qsjTPTp4Jl=s100"}}]}
```

