diff --git a/src/blocks/scratch3_looks.js b/src/blocks/scratch3_looks.js index e173ca04d..8c17bb1b0 100644 --- a/src/blocks/scratch3_looks.js +++ b/src/blocks/scratch3_looks.js @@ -251,7 +251,12 @@ class Scratch3LooksBlocks { say (args, util) { // @TODO in 2.0 calling say/think resets the right/left bias of the bubble - this._updateBubble(util.target, 'say', String(args.MESSAGE)); + let message = args.MESSAGE; + if (typeof message === 'number') { + message = message.toFixed(2); + } + message = String(message); + this.runtime.emit('SAY', util.target, 'say', message); } sayforsecs (args, util) { diff --git a/test/unit/blocks_looks.js b/test/unit/blocks_looks.js index 1506d7f84..6c1877c8a 100644 --- a/test/unit/blocks_looks.js +++ b/test/unit/blocks_looks.js @@ -1,5 +1,6 @@ const test = require('tap').test; const Looks = require('../../src/blocks/scratch3_looks'); +const Runtime = require('../../src/engine/runtime'); const util = { target: { currentCostume: 0, // Internally, current costume is 0 indexed @@ -50,3 +51,20 @@ test('getBackdropNumberName can return costume name', t => { t.strictEqual(number, 'third name'); t.end(); }); + +test('numbers should be rounded to two decimals in say', t => { + const rt = new Runtime(); + const looks = new Looks(rt); + + const args = {MESSAGE: 3.14159}; + const expectedSayString = '3.14'; + + rt.removeAllListeners('SAY'); // Prevent say blocks from executing + + rt.addListener('SAY', (target, type, sayString) => { + t.strictEqual(sayString, expectedSayString); + t.end(); + }); + + looks.say(args, util); +});