Calculation can't divide two variables

Comments

6 comments

  • Rainer Grabowski

    Hi Henrik,

    do you get the error "Number is not a function"? If so, remove the brackets ().
    You also get an error if var two = 0; JavaScript can't divide by 0. 

    Rainer 

    0
    Comment actions Permalink
  • Henrik Arvedsen

    Hi Rainer,
    I have tried without brackets as well.

    The error I get is in Danish but translated is:
    The result is not a whole number.

    0
    Comment actions Permalink
  • Rainer Grabowski

    Hi Henrik,

    I assume the correct translation is: Is not a valid number :) 
    Can you please share a screenshot of your calculation field which shows the code and the error message?
    Open an item, click "Tilpas skabelon", click into the calc field and make a screenshot. 

    Rainer

    0
    Comment actions Permalink
  • Bruce Catterall

    Hi Rainer,

    Same problem here, +,- and * all work as do integers. Neither variable is zero.

    Screenshot attached

    0
    Comment actions Permalink
  • Fabricio Klemenco

    Hello, i have also the same problem. Rainer, can you help us? Thank you

    0
    Comment actions Permalink
  • Rainer Grabowski

    You can try
    var a = Number(@field A) || 0;
    var b = Number(@field B) || 0;
    (a/b) || 0.

    But :  if b = 0 it doesn't give you a valid result because JavaScript can't divide by 0. So var b should be Number(@field B) || 1;
    If one of the fields is a number field you don't need Number(@field) || 0; you can use @field || 0 (or 1) 
    || 1 means = if this field is empty use the value 1. 

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk