Making Variables Round to Whole Number Rather Than to 2 Decimals

Feb 16, 2024

I have a pretty complex training I'm putting together using a lot of variables where numbers are being displayed with 1 or 2 decimal places. I want to force those numbers to show as rounded whole numbers. 

I saw in some old forum posts about passing said variable into a new variable, dividing by 10,000,000, then multiplying by 10,000,000, then passing it back into the original variable. But that did not work. The decimals remained.

Any way to easily do this? I have attached an example of the variables that I want to display as whole.

5 Replies
Walt Hamilton

As of yet, it seems that you should stay away from ChatGPT, as you will probably have to train it. Here is a script that will work

var player = GetPlayer();
 
var numValue = player.GetVar("NumericEntry");
var JSRoundedNum = numValue.toFixed(2);
player.SetVar("RoundedNum",JSRoundedNum);
 
NumericEntry is the name of your variable in SL, and RoundedNum is the name of the Text variable that it will return. (JS doesn’t distinguish between text and numeric variables, so SL considers them as text.)
Thomas Umphres

Walt,

Thanks so much. I got this working with a Javascript. I wish it was available in preview mode. I am just having to publish the individual slide to preview it. No biggie. 

Also, this has opened my eyes to how powerful javascripts can be. They might be a huge time saver and do things I didn't think I could do going forward. 

Thanks a ton.