Code to reduce the result of calc to 2 decimal places

I have a simple set of questions and code that works out take-off weight in a checklist for a Microlight (ULM). When doing the weight of MOGAS fuel I am using 0.75 and of course I get a load of decimals which I don’t need. I’d like to round up to just 2 decimal places or even to the next highest round number.

The code below is simple and I have two problems to solve

  1. a way to calculate the fuel value (litres) into a weight (say 30 * 0.75)
  2. and a way to only get 2 decimal places from the result above

The code I am using is:
${Number(P1) + Number(P2) + Number(Fuel) +Number(Bag) + 268} Kg

What code can I add to stop getting for example something like 425.666666785 kgs returned? Any ideas anyone, thanks in advance.

1 Like

Try…

${(Number(P1) + Number(P2) + Number(Fuel) + Number(Bag) + 268).toFixed(2)} Kg

toFixed(2) says to fix to 2 decimals. You need parenthesis around your full calculation first to use it as shown above.

1 Like