A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: math.round(); question

  1. #1
    Senior Member
    Join Date
    Nov 2000
    Posts
    265
    hello,

    is it possible to round a floating point number to a certain
    value?

    what i mean is:

    i want to round 1.85038723 to 1.8504

    (skip the last 4 numbers).

    is there a possibility?

    thx

  2. #2
    Senior Member
    Join Date
    Feb 2001
    Posts
    1,835
    here you go:

    Code:
    Math.roundDec = function (num,decPlaces) { 
    var p = Math.pow(10,decPlaces);
    return Math.round(num*p)/p;
    }
    slightly adapted from http://www.layer51.com/proto/d.asp?p=7&f=65

    - n.


  3. #3
    Senior Member
    Join Date
    Nov 2000
    Posts
    265
    thx enemem,

    you saved my life (well, nearly).




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center