Moodle
  1. Moodle
  2. MDL-28138

format_float function in question/type/calculated/db/upgradelib.php seems broken

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.1
    • Fix Version/s: 2.1
    • Component/s: Questions
    • Labels:
      None
    • Testing Instructions:
      Hide

      1. Run the unit tests in question
      2. Create calculated and calculated multi questions with various settings for 'Correct answer shows' and answer Format.
      3. Preview the question, and ensure that the answers are formatted properly.
      4. Switch to a language that uses , as decimal point, and re-preview the question.

      5. Test the upgrade 2.0 to 2.1 including attempts at calculated questions, and make sure there are no errors.

      Show
      1. Run the unit tests in question 2. Create calculated and calculated multi questions with various settings for 'Correct answer shows' and answer Format. 3. Preview the question, and ensure that the answers are formatted properly. 4. Switch to a language that uses , as decimal point, and re-preview the question. 5. Test the upgrade 2.0 to 2.1 including attempts at calculated questions, and make sure there are no errors.
    • Affected Branches:
      MOODLE_21_STABLE
    • Fixed Branches:
      MOODLE_21_STABLE
    • Pull from Repository:
    • Pull Master Branch:
    • Rank:
      18139

      Description

      format_float function in

      • question/type/calculated/db/upgradelib.php and
      • question/type/calculatedmulti/db/upgradelib.php
        seems broken

      If and else if have same condition in function format_float.

      public function format_float($x, $length = null, $format = null) {
          if (!is_null($length) && !is_null($format)) {
              if ($format == 1) {
                  // Decimal places.
                  $x = sprintf('%.' . $length . 'F', $x);
              } else if ($format == 1) {
                  // Significant figures.
                  $x = sprintf('%.' . $length . 'g', $x);
                  $x = str_replace(',', '.', $x);
              }
          }
          return $x;
      }
      

        Issue Links

          Activity

          Hide
          Tim Hunt added a comment -

          I created MDL-28142 for the use of magic numbers not named constants for $format throughout this qtype.

          Am about to write some unit tests then fix the code.

          Show
          Tim Hunt added a comment - I created MDL-28142 for the use of magic numbers not named constants for $format throughout this qtype. Am about to write some unit tests then fix the code.
          Hide
          Sam Hemelryk added a comment -

          Thanks Tim - integrated now.
          Raj if you have a moment are you able to test this for us?

          Show
          Sam Hemelryk added a comment - Thanks Tim - integrated now. Raj if you have a moment are you able to test this for us?
          Hide
          Rajesh Taneja added a comment -

          Works Great Tim
          Thanks for providing the patch.

          Show
          Rajesh Taneja added a comment - Works Great Tim Thanks for providing the patch.
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Yay, this is now part of the just released Moodle 2.1 ! Thanks for all the hard work!

          Show
          Eloy Lafuente (stronk7) added a comment - Yay, this is now part of the just released Moodle 2.1 ! Thanks for all the hard work!

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: