# Math.round or Math.floor

**URL:** <https://forum.kirupa.com/t/math-round-or-math-floor/8104>\
**Category:** flash\
**Created:** [November 13, 2002, 11:10pm UTC](https://forum.kirupa.com/t/math-round-or-math-floor/8104 "2002-11-13T23:10:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kornkid8281](https://avatars.discourse-cdn.com/v4/letter/k/c67d28/32.png) [@kornkid8281](https://forum.kirupa.com/u/kornkid8281)\
**Post date:** [November 13, 2002, 11:10pm UTC](https://forum.kirupa.com/t/math-round-or-math-floor/8104/1 "2002-11-13T23:10:01Z")

</div>

i want to round a decimal to like 1.5. here’s what i have:  
\<hr\>Math.floor((smallNum/bigNum)\*100)\<hr\>

is there something i can do to this so that it’ll round to like 11.5?

---

<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:** [November 14, 2002, 1:30am UTC](https://forum.kirupa.com/t/math-round-or-math-floor/8104/2 "2002-11-14T01:30:59Z")

</div>

here’s a function (which i put in the Math object, but could go anywhere) which rounds “n” number to “d” decimal.

```auto

Math.roundTo = function(n,d){
	return Math.round(n/d) * d;
}

```

so if num = 1294.2258

Math.roundTo(num,.1) would return 1294.2  
Math.roundTo(num,10) returns 1290

and so on

---

<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:** [November 14, 2002, 2:56am UTC](https://forum.kirupa.com/t/math-round-or-math-floor/8104/3 "2002-11-14T02:56:24Z")

</div>

thank you so much! that was the perfect solution!
