Jump to content

How to change the number of digits displayed in a value ?

Jasmin Helstein

Recommended Posts


I do have hud that tells me my speed when I am moving. The speed displayed in the hud comes from this line in the script:

          llSetText((string)llRound((7.2 * aftervalue)) + " kph", <1,0,0>, 1);

This gives a rounded value in whole kilometers per hour. If I leave out the "llRound" the value will be displayed with six decimals and I do want it displayed with only one. How should i do this ?



Link to comment
Share on other sites

I had a play with this, trying to round the single decimal up or down, depending on what the second decimal is.

There's probably a more elegant way of doing it, but this is what I came up with:


default{	state_entry()	{		float f =125.267591;// some number		integer i = llFloor(f);		float temp = f -(float)i;		string str = (string)temp;		llOwnerSay("str is "+str);		if((integer)(llGetSubString(str,3,3))>5){			temp+=0.1;		}		f = (float)i+temp;		str = (string)f;		str = llGetSubString(str,0,llSubStringIndex(str,".")+1);		llOwnerSay(str);	}}


Link to comment
Share on other sites

My 0.02 L$:

string round( float F, integer decimals ) {    decimals = llAbs(decimals);    F = llRound(F * llPow(10, decimals)) / llPow(10, decimals);    list temp = llParseString2List((string)F, ["."], []);    string left = llList2String(temp, 0);    string right;    if(decimals) right = "." + llGetSubString(llList2String(temp, 1), 0, decimals - 1);       return left + right;} default {    state_entry() {        llOwnerSay(round(456.94575824, 0));    }}


Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now
  • Create New...