# How to round a number

**URL:** <https://forum.wixstudio.com/t/how-to-round-a-number/27834>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [January 30, 2020, 4:00pm UTC](https://forum.wixstudio.com/t/how-to-round-a-number/27834 "2020-01-30T16:00:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpvac](https://avatars.discourse-cdn.com/v4/letter/j/a5b964/32.png) [@jpvac](https://forum.wixstudio.com/u/jpvac)\
**Post date:** [January 30, 2020, 4:00pm UTC](https://forum.wixstudio.com/t/how-to-round-a-number/27834/1 "2020-01-30T16:00:24Z")

</div>

Does anybody know how to round a number that is displayed? (two or three decimal places max)  
So I have:  
export function button3\_click(event) {

let A=Number($w(“#input127”).value);  
let B=Number($w(“#input128”).value);  
let C=Number($w(“#input129”).value);  
let D =Number($w(“#input130”).value);  
let Resultado5 = A_B_(1-C)+A/C  
**let** Resultado3 = Resultado5/D  
$w(“#text44”).text = Resultado3.toString();  
}  
The problem is that the result is always shown with a lot of decimal places…

---

<div class="post-metadata">

**Author:** ![tony-brunsman](https://avatars.discourse-cdn.com/v4/letter/t/ea5d25/32.png) [@tony-brunsman](https://forum.wixstudio.com/u/tony-brunsman)\
**Post date:** [January 30, 2020, 5:43pm UTC](https://forum.wixstudio.com/t/how-to-round-a-number/27834/2 "2020-01-30T17:43:06Z")

</div>

@jpvac A function needs to be written to handle this.

```javascript
function RoundDecimal(num, dec){
    // in case number is less than 0
    let GrLessZero = num >= 0 ? 1 : -1;
    return (Math.round((num * Math.pow(10, dec)) + (GrLessZero * 0.0001)) 
    /Math.pow(10, dec)).toFixed(dec);
}

```

Follow links for some documentation of the functions used.

---

<div class="post-metadata">

**Author:** ![jpvac](https://avatars.discourse-cdn.com/v4/letter/j/a5b964/32.png) [@jpvac](https://forum.wixstudio.com/u/jpvac)\
**Post date:** [February 3, 2020, 3:15pm UTC](https://forum.wixstudio.com/t/how-to-round-a-number/27834/3 "2020-02-03T15:15:33Z")

</div>

Thank you man, but how do I associate my “Resultado3” with that function?

---

<div class="post-metadata">

**Author:** ![tony-brunsman](https://avatars.discourse-cdn.com/v4/letter/t/ea5d25/32.png) [@tony-brunsman](https://forum.wixstudio.com/u/tony-brunsman)\
**Post date:** [February 3, 2020, 8:57pm UTC](https://forum.wixstudio.com/t/how-to-round-a-number/27834/4 "2020-02-03T20:57:19Z")

</div>

@jpvac This is the function call for 2 decimal places:

```javascript
let Resultado3 = RoundDecimal(Resultado5/D,2);

```

---

<div class="post-metadata">

**Author:** ![user107](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/user107/32/80954_2.png) [@user107](https://forum.wixstudio.com/u/user107)\
**Post date:** [August 17, 2023, 3:55am UTC](https://forum.wixstudio.com/t/how-to-round-a-number/27834/5 "2023-08-17T03:55:14Z")

</div>

You my friend, save my life! Cheers!
