# Rounding

**URL:** <https://forum.kirupa.com/t/rounding/29318>\
**Category:** flash\
**Created:** [August 25, 2003, 6:04pm UTC](https://forum.kirupa.com/t/rounding/29318 "2003-08-25T18:04:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![grandsp5](https://avatars.discourse-cdn.com/v4/letter/g/6bbea6/32.png) [@grandsp5](https://forum.kirupa.com/u/grandsp5)\
**Post date:** [August 25, 2003, 6:04pm UTC](https://forum.kirupa.com/t/rounding/29318/1 "2003-08-25T18:04:17Z")

</div>

is there an easy way to specify how many digits after the decimal flash will return in a variable. I know you can do it in a sort of complicated way like this:  
[AS]  
//say i want 3 decimal places out of number  
number = 100.12345  
number \*= 1000;  
Math.round(number);  
number /= 1000;  
[/AS]

but is there a better way, something like  
Math.roundPlaces(number, 3);  
?  
thanks

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 25, 2003, 6:11pm UTC](https://forum.kirupa.com/t/rounding/29318/2 "2003-08-25T18:11:51Z")

</div>

not that i know of ☹  
but this is shorter 😉

```auto

number = Math.round(number*1000)/1000;

```

:}

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 25, 2003, 6:13pm UTC](https://forum.kirupa.com/t/rounding/29318/3 "2003-08-25T18:13:08Z")

</div>

🙂 thanks master 64 but I was just wondering if there was a better way. sadly, i guess not.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 25, 2003, 6:22pm UTC](https://forum.kirupa.com/t/rounding/29318/4 "2003-08-25T18:22:24Z")

</div>

```auto

function roundDecs(number, decs){
var timesBy = Math.pow(10, decs);
return Math.round(number*timesBy)/timesBy
}

```

😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [August 25, 2003, 6:24pm UTC](https://forum.kirupa.com/t/rounding/29318/5 "2003-08-25T18:24:09Z")

</div>

ooh nice. make it into a nifty little function. 😉 ok that should work for what I need. Thanks a bunch guys.
