# How do I round a JavaScript number to 2 decimal places?

**URL:** https://discourse.nodered.org/t/how-do-i-round-a-javascript-number-to-2-decimal-places/64571
**Category:** General
**Tags:** node-red-dashboard, function-node
**Created:** [1 July 2022 06:19 UTC](https://discourse.nodered.org/t/how-do-i-round-a-javascript-number-to-2-decimal-places/64571 "2022-07-01T06:19:15Z")
**Posts on this page:** 3
**Page:** 2

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [13 August 2022 12:52 UTC](https://discourse.nodered.org/t/how-do-i-round-a-javascript-number-to-2-decimal-places/64571/21 "2022-08-13T12:52:58Z")

</div>

> [@Steve-Mcl](#):
>
> done by the digit to the right of the one you are rounding

Well that probably tells you everything you need to know about my school performance 🤣

Interestingly, even 64bit Excel won't accept `1511000000005.2148`, it will only take 2dp no matter what you do. `5.2148` is, of course fine. And yes, it rounds the shorter number to `5.21` as you expect.

Even more interesting in Excel. If you take the text of '1511000000005.2148' and use the formula `=NUMBERVALUE("1511000000005.2148")-1511000000005`, you get an answer of `0.2099609375`

Which is, I think, a useful reminder that large numbers don't always do what you expect when working with computers.

OK, OK, yes I've now completely side-tracked my Saturday afternoon!! But using Excel's PowerQuery tools, you do get slightly more accurate results with such a large number. The same calculation as above gives an answer of 0.21484375.

Right, back to your normal content 🕶

---

<div class="post-metadata">

### Author: ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)
#### Post date: [14 August 2022 22:29 UTC](https://discourse.nodered.org/t/how-do-i-round-a-javascript-number-to-2-decimal-places/64571/22 "2022-08-14T22:29:30Z")

</div>

> [@TotallyInformation](#):
>
> Well that probably tells you everything you need to know about my school performance

I bet you were one of those kids where they said - "Could do better if he just tried" on the report card !!

And look how he has now blossomed !

Craig

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [23 September 2022 05:29 UTC](https://discourse.nodered.org/t/how-do-i-round-a-javascript-number-to-2-decimal-places/64571/23 "2022-09-23T05:29:35Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

[Previous page](https://discourse.nodered.org/t/how-do-i-round-a-javascript-number-to-2-decimal-places/64571.md?page=1)
