Announcement

Collapse
No announcement yet.

Help with decimal manipulation

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

  • Help with decimal manipulation

    Can someone show me in this code how to use the rounding function(s) so this IBM plot has no decimal plotting on a chart. ie. 118 instead of 118.45. I'm trying to figure out how the rounding functions work in code.

    function premain() {
    setPriceStudy(true);
    setStudyTitle("vDecimal");
    setCurserLabelName("DEC");
    setDefaultBarFgColor(Color.blue,0);
    setDefaultBarThickness(2);
    setPlotType(PLOTTYPE_LINE,0);
    }

    var mySym = null;
    //var myDecimal = null;

    function main() {

    var mySym = close(0,sym("IBM"));

    return(mySym);
    }

  • #2
    Re: Help with decimal manipulation

    huntergatherer
    Depending on the desired result there are several ways you can do what you want
    One is to just use the round() method of the Math Object eg
    var myDecimal = Math.round(mySym)
    For the description and syntax of the Math Object see the link to the corresponding article in the EFS KnowledgeBase
    Alex


    Originally posted by huntergatherer
    Can someone show me in this code how to use the rounding function(s) so this IBM plot has no decimal plotting on a chart. ie. 118 instead of 118.45. I'm trying to figure out how the rounding functions work in code.

    function premain() {
    setPriceStudy(true);
    setStudyTitle("vDecimal");
    setCurserLabelName("DEC");
    setDefaultBarFgColor(Color.blue,0);
    setDefaultBarThickness(2);
    setPlotType(PLOTTYPE_LINE,0);
    }

    var mySym = null;
    //var myDecimal = null;

    function main() {

    var mySym = close(0,sym("IBM"));

    return(mySym);
    }

    Comment


    • #3
      Thanks for the help Alex.

      Is this the right syntax for:
      var myDecimal = formatPriceNumber(mySym)*1;
      and
      var myDecimal = mySym.tofixed(0)*1 //where toFixed(0) = no decimal.

      Comment


      • #4
        huntergatherer
        The syntax is correct however keep in mind that it will not round the values [which is what I believe you asked initially]
        Alex


        Originally posted by huntergatherer
        Thanks for the help Alex.

        Is this the right syntax for:
        var myDecimal = formatPriceNumber(mySym)*1;
        and
        var myDecimal = mySym.tofixed(0)*1 //where toFixed(0) = no decimal.

        Comment

        Working...
        X