facebook

Is log10() supported?

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #342286 Reply

    mp3cdr
    Member

    Is log10() supported in the java script by mobi one?

    I only seem to be able to use log().

    Thanks,
    Dave

    #342287

    support-michael
    Keymaster

    javascript math.log() returns the natural log base ‘e’. To convert to base 10 use the following:

    
      Math.log(num) / Math.LN10;
    

    You can google up more conversation on this, e.g., http://stackoverflow.com/questions/3019278/any-way-to-specify-the-base-of-math-log-in-javascript

    #342314

    mp3cdr
    Member

    Thanks for the input and seems to work but how do I get past the precision issues with this?

    e.g.
    > Math.log(10)/Math.LN10
    1

    > Math.log(100)/Math.LN10
    2

    > Math.log(1000)/Math.LN10
    2.9999999999999996 // When using calculator Log10(1000) the answer = “3”

    > Math.log(10000)/Math.LN10
    4

    Thanks,
    dave

    #342316

    Brandon
    Member

    try using the javascript round() to process the result.

    #342318

    support-michael
    Keymaster

    additionally you may want might find the toFixed() to set the decimal precision useful. See
    http://www.w3schools.com/jsref/jsref_tofixed.asp

Viewing 5 posts - 1 through 5 (of 5 total)
Reply To: Is log10() supported?

You must be logged in to post in the forum log in