Jasmin Helstein Posted October 1, 2013 Share Posted October 1, 2013 Hi,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 ?thanks,Jasmin Link to comment Share on other sites More sharing options...
Rolig Loon Posted October 1, 2013 Share Posted October 1, 2013 1. Convert the value to a string variable. 2. Use llSubStringIndex(my_number,".") to find the decimal point. 3. Delete the substring that begins one character after the decimal point. Link to comment Share on other sites More sharing options...
Innula Zenovka Posted October 1, 2013 Share Posted October 1, 2013 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 More sharing options...
Dora Gustafson Posted October 1, 2013 Share Posted October 1, 2013 Another bid: default{ touch_start(integer total_number) { float x = llFrand( 100.0); string s = (string)llRound(10.0*x); llOwnerSay( llGetSubString( s, 0, -2)+"."+llGetSubString( s, -1, -1)); }} :smileysurprised::smileyvery-happy: Link to comment Share on other sites More sharing options...
Ron Khondji Posted October 2, 2013 Share Posted October 2, 2013 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 More sharing options...
Jasmin Helstein Posted October 2, 2013 Author Share Posted October 2, 2013 Pfffft ... It took some effort but I figured it out. Thank you very much for the help everyone ! Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now