This content has been marked as final.
Show 4 replies

1. Re: round decimal fraction to certain digits after the dot
Newsgroup_User May 23, 2006 2:05 AM (in response to Newsgroup_User)Hi!
I made a function for you. Maybe not the best name, but you can call it what
you want ;)
function roundToDigit(num:Number, nrOfDigits:Number):Number {
var factor = Math.pow(10,nrOfDigits)
return Math.round(num*factor)/factor;
}
trace(roundToDigit(3.1416,2));
/Jensen/
"aa" <A@aa.com> wrote in message news:e4uiu7$g2j$1@forums.macromedia.com...
> Is there a function to round a decimal fraction to certain digits after
> the
> dot?
> eg.: 3.1416 > 3.14
>
>

2. Re: round decimal fraction to certain digits after the dot
Newsgroup_User May 23, 2006 2:23 AM (in response to Newsgroup_User)Thanks, Jensen, it works and the name is apt.
Do you mean that there is no built in function in Math object?

3. Re: round decimal fraction to certain digits after the dot
Newsgroup_User May 23, 2006 2:26 AM (in response to Newsgroup_User)Nope, no such function in the Math object (as far as I can see). Note you
also have the Math.ceil and Math.floor functions if you want to round up or
down.
"aa" <A@aa.com> wrote in message news:e4ukae$hm3$1@forums.macromedia.com...
> Thanks, Jensen, it works and the name is apt.
> Do you mean that there is no built in function in Math object?
>
>

4. Re: round decimal fraction to certain digits after the dot
skot:317 Jul 11, 2007 10:23 AM (in response to Newsgroup_User)One problem I found with this is that 22.29683 becomes 22.3, not 22.30. I'm using this to convert for dollar amounts and I need that 0 penny in there.
Any ideas?