SparkAR javascript toFixed(1) is not work

123 Views Asked by At

Here's the relevant code.

"counter.text = scorestring.toFixed(1).toString();"

I am not sure the code below is correct.

const Scene = require('Scene');
const Patches = require('Patches');

Promise.all([
    
    Scene.root.findFirst('number'),
    Patches.outputs.getScalar('score'),
    Scene.root.findFirst('timer'),
    Patches.outputs.getScalar('timer_sec')

]).then(function(results){
    var counter = results[0];
    var scorestring = results[1];
    var counter2 = results[2];
    var timerstring = results[3];

    counter.text = scorestring.toFixed(1).toString();

    counter2.text = timerstring.toString();
})

SparkAR preview:

screen of SparkAR preview

1

There are 1 best solutions below

2
On

ScalarSignal class should be formatted with:

format(formatString: string): StringSignal

The formatString rules as specified here: https://github.com/facebook/folly/blob/master/folly/docs/Format.md#format-string-syntax .

In your scenario:

counter.text = scorestring.format("You can also add text here {:.1f}");