Announcement

Collapse
No announcement yet.

True value of a moving average

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • True value of a moving average

    The cursor window shows the moving average as a whole number; for example 8925. But when I reference the moving average within the efs, the value is 0.892500000000005. The whole number vs. the decimal is not the issue. My question is why is there an extraneous digit on the far right?

    I am trying to compare the moving average value to the close value. Both of them are .8925 but they are not equal because of the digit on the far right. What is that last digit for? But more importantly, how do I get rid of it in the efs so my compare is valid?
    Thank you.

  • #2
    Re: True value of a moving average

    pjkowalski
    In JavaScript [hence in EFS] numbers are represented as floating point numbers. This can result in some numbers containing an extreme precision such as 43.62000000000005.
    The solution is to apply the .toFixed() method of the number object to limit the number of decimals. Keep in mind that the .toFixed() method converts a number to a string so if you instead need it as a number you need to convert it back by multiplying it by 1 eg myValue.toFixed(4)*1
    Alternatively you can use the formatPriceNumber() function to do the same with the advantage that you do not need to define the number of decimals (note that it also converts the number to a string)
    See the EFS KnowledgeBase for the description and syntax of these functions
    Alex


    Originally posted by pjkowalski
    The cursor window shows the moving average as a whole number; for example 8925. But when I reference the moving average within the efs, the value is 0.892500000000005. The whole number vs. the decimal is not the issue. My question is why is there an extraneous digit on the far right?

    I am trying to compare the moving average value to the close value. Both of them are .8925 but they are not equal because of the digit on the far right. What is that last digit for? But more importantly, how do I get rid of it in the efs so my compare is valid?
    Thank you.

    Comment

    Working...
    X