Announcement

Collapse
No announcement yet.

Math Infinity

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

  • Math Infinity

    The following snippet of code returns Infinity. How do I get a valid result out of the calculation? It works fine in Internet Explorer Javascript, but not in EFS.

    Thanks,
    Steven

    ---------------------------------
    var Num = 5.75
    var Den = 6;

    var Result = Num / Den * 100;
    ---------------------------------

  • #2
    Steven
    It appears to be returning a valid number albeit with a lot of decimals.
    The script below shows an example of how to limit the decimals using toFixed(n) if that is what you are looking for
    Alex

    PHP Code:
    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("Num/Den");
        
    setShowCursorLabel(false);  
    }

    function 
    main() {

    var 
    Num 5.75;
    var 
    Den 6;
    var 
    Result Num Den 100;

    drawTextRelative(3,high(),Result,Color.blue,Color.white,Text.BOTTOM|Text.BOLD,"Arial",11,"Up");
    drawTextRelative(3,low(),Result.toFixed(2),Color.blue,Color.white,Text.TOP|Text.BOLD,"Arial",11,"Dn");

    return;

    Comment

    Working...
    X