4 Replies Latest reply on Mar 25, 2017 4:07 PM by jackh8500410

    Getting 2 decimal places

    jackh8500410 Level 1

      Hi all,

       

      I'm trying to get one of my maths equations to be rounded to 2 decimal places, but when I do this, it rounds it too much.

      The code I've been experimenting with:

      var decimalPlace1: Number = Math.round(mLvl1Qu5RanNu1 * 10) / 100;

      trace("decimalPlace1", decimalPlace1);

      var decimalPlace2: Number = Math.round(mLvl1Qu5RanNu2 * 10) / 100;

      trace("decimalPlace2", decimalPlace2);

      var mLvl1Qu5Equal = decimalPlace1 - decimalPlace2;

      trace("equals", mLvl1Qu5Equal);

      var mLvl1Qu5EqualDecimal = Math.round(mLvl1Qu5Equal * 10) / 100;

      trace("mLvl1Qu5EqualDecimal", mLvl1Qu5EqualDecimal);

       

      The output

      decimalPlace1 50.99

      decimalPlace2 35.32

      equals 15.670000000000002

      mLvl1Qu5EqualDecimal 1.57

       

      I got it working without the code in bold, but for some reason it's stopped working again.

       

      I need to check the answer of mLvl1Qu5Equal against what the user enters.

       

      Thanks,

      Jack