Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Rounding with a decimal

Relatively simple question for Sugarcube 2.

<<set $var3 to Math.round($var1 / $var2)>>

If $var1 is 9 and $var2 is 7, the answer would be 1.28571428571, or 1 with the Math.round function. Is there a way to have it display just 1.2 or 1.28?


  • There are various ways to do it. The following is one:
    /* Limit to 2 decimal places. */
    <<set $var3 to Number(($var1 / $var2).toFixed(2))>>
    /* Limit to 1 decimal place. */
    <<set $var3 to Number(($var1 / $var2).toFixed(1))>>
Sign In or Register to comment.