# Format Percentage (with precision)

**URL:** <https://forum.kirupa.com/t/format-percentage-with-precision/287730>\
**Category:** flash\
**Created:** [May 5, 2009, 5:32pm UTC](https://forum.kirupa.com/t/format-percentage-with-precision/287730 "2009-05-05T17:32:41Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alpha\_Remex](https://avatars.discourse-cdn.com/v4/letter/a/779978/32.png) [@Alpha\_Remex](https://forum.kirupa.com/u/Alpha_Remex)\
**Post date:** [May 5, 2009, 5:32pm UTC](https://forum.kirupa.com/t/format-percentage-with-precision/287730/1 "2009-05-05T17:32:41Z")

</div>

Ok, so I’ve read quite a bit on formatting and I’m good to go on currency, numbers with commas, etc.

I’ve been trying for awhile to format a percent number and I’ve gotten relatively close to where I want to be:

```auto

public static function percent(n:Number):String {
            
            //Converts the argument to a string with the percentage symbol
            var output:String = Math.ceil(n*100).toString() + "%";

            //Returns the reformatted percentage
            return output;
        }

```

The problem here is that I need to be able to set precision and I keep messing it up when I try to write something… here’s an example:

**Number:** 0.203948278358292  
**Result with the above code:** 20%  
**Desired Result:** 20.39%

Can anyone help me with this?🔗
