From a2db2f2851dbc55db591ee97e30c82b6f469f560 Mon Sep 17 00:00:00 2001 From: Sotiri Bakagiannis Date: Fri, 19 Feb 2021 14:11:08 +0000 Subject: [PATCH] data/TrialHandler: tweak numerical string typecasting --- js/data/TrialHandler.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/js/data/TrialHandler.js b/js/data/TrialHandler.js index d9deab8..ecb1d2d 100644 --- a/js/data/TrialHandler.js +++ b/js/data/TrialHandler.js @@ -482,11 +482,18 @@ export class TrialHandler extends PsychObject if (typeof value === 'string') { - // Parse doubly escaped line feeds - value = value.replace(/(\\n)/g, '\n'); + const numberMaybe = Number.parseFloat(value); // if value is a numerical string, convert it to a number: - value = isNaN(value) ? value : Number.parseFloat(value); + if (!isNaN(numberMaybe) && numberMaybe.toString().length === value.length) + { + value = numberMaybe; + } + else + { + // Parse doubly escaped line feeds + value = value.replace(/(\n)/g, '\n'); + } } trial[fields[l]] = value;