# The Case of the Repeating Decimal - JS calculator

**URL:** <https://forum.freecodecamp.org/t/the-case-of-the-repeating-decimal-js-calculator/46931>\
**Category:** I Built This\
**Created:** [October 19, 2016, 1:47pm UTC](https://forum.freecodecamp.org/t/the-case-of-the-repeating-decimal-js-calculator/46931 "2016-10-19T13:47:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Docwali777](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/docwali777/32/65065_2.png) [@Docwali777](https://forum.freecodecamp.org/u/Docwali777)\
**Post date:** [October 19, 2016, 1:47pm UTC](https://forum.freecodecamp.org/t/the-case-of-the-repeating-decimal-js-calculator/46931/1 "2016-10-19T13:47:37Z")

</div>

Here is my code for the JS calculator - [http://codepen.io/docwali777/pen/ALPGBm](http://codepen.io/docwali777/pen/ALPGBm)

How do I prevent multiple decimals from being added…?

---

<div class="post-metadata">

**Author:** ![IsaacAbrahamson](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/isaacabrahamson/32/30882_2.png) [@IsaacAbrahamson](https://forum.freecodecamp.org/u/IsaacAbrahamson)\
**Post date:** [October 19, 2016, 1:52pm UTC](https://forum.freecodecamp.org/t/the-case-of-the-repeating-decimal-js-calculator/46931/2 "2016-10-19T13:52:12Z")

</div>

> [@Docwali777](#):
>
> Here is my code for the JS calculator - [http://codepen.io/docwali777/pen/ALPGBm](http://codepen.io/docwali777/pen/ALPGBm)
> 
> How do I prevent multiple decimals from being added…?

Modify your decimal code to no longer add if number contains decimal, I just wrote this as example on the fly:

```auto
$("#period").click(function() {
    if ($("#numberInput").text().indexOf('.') == -1) {
        $("#numberInput").append(".");
    }
});

```

---

<div class="post-metadata">

**Author:** ![Docwali777](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/docwali777/32/65065_2.png) [@Docwali777](https://forum.freecodecamp.org/u/Docwali777)\
**Post date:** [October 19, 2016, 2:05pm UTC](https://forum.freecodecamp.org/t/the-case-of-the-repeating-decimal-js-calculator/46931/4 "2016-10-19T14:05:43Z")

</div>

Thank you very much… It worked…!!!

I solved two problem with your solutions…

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 6:04pm UTC](https://forum.freecodecamp.org/t/the-case-of-the-repeating-decimal-js-calculator/46931/5 "2021-06-01T18:04:43Z")

</div>

Closed on June 1, 2021, 6:04pm UTC


