Limiting Decimal Places

Viewing 1 reply thread
  • Author
    Posts
  • February 21, 2020 at 3:16 AM #39608

    Barry Shevlin
    Participant

    I’m almost embarrassed to ask this given it’s probably such a basic question. However, I could well use the following script given as an example in the TF5 manual:

    var records = form.getRecords();
    var revenue_total = 0;

    for (var index = 0, count = records.length; index < count; index++){
    var theRec = records[index];
    var movie_revenue = theRec.getFieldValue(‘fld-987c9aac738a4f0fa1d18395902b3fc1’);
    if (movie_revenue) {
    revenue_total += movie_revenue;
    console.log(‘Revenue: ‘ + movie_revenue);
    }
    }

    revenue_total;

    My question is this: how do I limit the revenue_total return to 2 decimal places (currency)? I am getting this sort of thing: £63.9300000000001.

    Sorry if this time-wasting but I’m sure there’s a quick answer that would save me hours of fruitless futzing. Thanks.

    February 22, 2020 at 12:08 AM #39616

    Sam Moffatt
    Participant

    Try revenue_total.toFixed(2); as your last line and see if that gives you the desired effect.

    As a lateral answer, you can configure the script field with a particular format. If you reconfigure your script field to use a “Number” return type, you can then use the number formatting options in the field configuration to have it display the way you want.

Viewing 1 reply thread

You must be logged in to reply to this topic.