# Rounding Decimals function?

**URL:** <https://forum.kirupa.com/t/rounding-decimals-function/311795>\
**Category:** Uncategorized\
**Created:** [July 16, 2010, 2:27pm UTC](https://forum.kirupa.com/t/rounding-decimals-function/311795 "2010-07-16T14:27:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![johnnytwotimes](https://avatars.discourse-cdn.com/v4/letter/j/c2a13f/32.png) [@johnnytwotimes](https://forum.kirupa.com/u/johnnytwotimes)\
**Post date:** [July 16, 2010, 2:27pm UTC](https://forum.kirupa.com/t/rounding-decimals-function/311795/1 "2010-07-16T14:27:51Z")

</div>

Hi guys!

I’ve used this site for years - it’s usally the top result when i’m looking for as2/flash help - i know your all experts so my question may sound stupid :ne:

All the guides/info on rounding decimals - do not do what i want, and i cannot work it out. The main guide is adobe itself…

[http://kb2.adobe.com/cps/155/tn\_15542.html](http://kb2.adobe.com/cps/155/tn_15542.html)

```auto

value= Math.round(20/7); // 0 DP - eg. 3  
value= int((20/7)*10)/10; // 1 DP - eg. 2.8  
value= int((20/7)*100)/100; // 2 DP - eg. 2.85  
value= int((20/7)*1000)/1000; // 3 DP - eg. 2.857  
value= int((20/7)*10000)/10000; // 4 DP - eg. 2.85 71  

```

However, what i would want is, if the number is: 0.00189

To have a way to turn it into:

0DP = 1.00  
1DP = 0.10  
2DP = 0.103DP = 0.002  
4DP = 0.0019

The code from adobe would produce this:

0DP = 0  
1DP = 0  
2DP = 0  
3DP = 0.001  
4DP = 0.0018

I think adobe’s code just CUTs the number off a the DP - where as i would like it to round up to the nearest DP. It’s for working with $$$.

Thanks so much for reading this long post!

Cheers! 🙂
