Skip to content

Commit 1c97720

Browse files
committed
Matrix entry part: apply the precision settings to numbers in pre-filled cells.
fixes #1133
1 parent 07a2871 commit 1c97720

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

runtime/scripts/parts/matrixentry.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ MatrixEntryPart.prototype = /** @lends Numbas.parts.MatrixEntryPart.prototype */
142142
['minColumns','maxColumns','minRows','maxRows'].map(eval_setting);
143143
}
144144

145+
settings.tolerance = Math.max(settings.tolerance,0.00000000001);
146+
if(settings.precisionType != 'none') {
147+
settings.allowFractions = false;
148+
}
149+
150+
this.getCorrectAnswer(scope);
151+
145152
var prefilled_fractions = settings.allowFractions && settings.correctAnswerFractions;
146153
if(settings.prefilledCellsString) {
147154
var prefilledCells = jme.castToType(scope.evaluate(jme.subvars(settings.prefilledCellsString+'',scope)), 'list');
@@ -172,7 +179,7 @@ MatrixEntryPart.prototype = /** @lends Numbas.parts.MatrixEntryPart.prototype */
172179
return frac.toString();
173180
} else {
174181
cell = jme.castToType(cell,'number');
175-
return math.niceRealNumber(cell.value,scope);
182+
return math.niceRealNumber(cell.value, {precisionType: settings.precisionType, precision: settings.precision, style: settings.correctAnswerStyle});
176183
}
177184
}
178185
p.error('part.matrix.invalid type in prefilled',{type: cell.type});
@@ -181,10 +188,6 @@ MatrixEntryPart.prototype = /** @lends Numbas.parts.MatrixEntryPart.prototype */
181188
}
182189
}
183190

184-
settings.tolerance = Math.max(settings.tolerance,0.00000000001);
185-
if(settings.precisionType!='none') {
186-
settings.allowFractions = false;
187-
}
188191
this.studentAnswer = [];
189192
for(var i=0;i<this.settings.numRows;i++) {
190193
var row = [];
@@ -193,7 +196,6 @@ MatrixEntryPart.prototype = /** @lends Numbas.parts.MatrixEntryPart.prototype */
193196
}
194197
this.studentAnswer.push(row);
195198
}
196-
this.getCorrectAnswer(scope);
197199
if(!settings.allowResize && (settings.correctAnswer.rows!=settings.numRows || settings.correctAnswer.columns != settings.numColumns)) {
198200
var correctSize = settings.correctAnswer.rows+'×'+settings.correctAnswer.columns;
199201
var answerSize = settings.numRows+'×'+settings.numColumns;

0 commit comments

Comments
 (0)