Number format in table in calculation field



  • Richard Hedger (Niton)

    Solved it myself - here's an example solution with the result. Note the use of hyperlinks to relevant documents in related apps

    Comment actions Permalink
  • Rainer Grabowski

    A tip: If you need to format not only one number (e.g. if you have a table with number values in multiple columns) you don't need to repeat 
    "CHF" + variable[i].toFixed(2).replace(...).replace(...) for each variable. You can use a function:

    function formatNum(number){
    if (typeof number === "undefined" || number == null || number== "NaN" ) number = 0;
    return "CHF " + number.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, "'")   

    Put that function code somewhere above the for-loop.
    Then call the function wherever you need it to format a number as amount, e.g.

    lines.push(numCur(variable1[i]) + " | " + numCur(variable2[i]) + " | " + numCur(variable3[i]));

    Btw. The first .replace(".",".") in your code you can remove cause it doesn't make sense to replace a dot with a dot :) 


    Comment actions Permalink
  • Richard Hedger (Niton)

    Rainer, thanks for the advice...I will give a try.

    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk