xinaesthete / dat.guiVR

A flexible graphical user interface for changing variables within WebVR.
https://workshop.chromeexperiments.com/examples/guiVR/
Apache License 2.0
9 stars 4 forks source link

small numbers format wrong #14

Closed sjpt closed 5 years ago

sjpt commented 5 years ago

Small numbers format as 0 in slider boxes. Replace roundToDecimal with something like:

function roundToDecimal(value, decimals) {
    if (Math.abs(value) < 0.01 && value !== 0) return value.toExponential(3);  
    var tenTo = Math.pow(10, decimals); 
    return Math.round(value * tenTo) / tenTo;
}

n.b. do NOT use value.toExponential(decimals)