Jump to content
Alert23

Remove digits after comma

Recommended Posts

Hi everyone,

 

i have this script to display the vehicle speed and it does work:

 

[] spawn {while {alive vehicle player} do {  
  
 		_displaySpeed = speed vehicle player;  
   		[format ["%1", _displaySpeed],-0.99,-0.15,9999,0,0,202] spawn BIS_fnc_dynamicText;  
   		sleep 0.1;  
 	}; 
};

but it shows too much digits after the comma:

TPxennBW.jpg

how can i remove the digits after comma?

thank you for your help.

Share this post


Link to post
Share on other sites

To get rid of any digits after the comma you can always use floor. Also use an eachframe EH to make it look smooth:

addMissionEventhandler ["EachFrame",{
	if (alive vehicle player) then {
 		_displaySpeed = floor speed vehicle player;  
   		[format ["%1", _displaySpeed],-0.99,-0.15,9999,0,0,202] spawn BIS_fnc_dynamicText;
	}
}]

Consider being more descriptive when picking a thread title, since you already went through the effort to make a screenshot, might as well decide for a more descriptive title.

 

Cheers

  • Thanks 1

Share this post


Link to post
Share on other sites

thank you both, both solution are working.

thank you again!

edit: changed thread title.

Share this post


Link to post
Share on other sites
17 minutes ago, Grumpy Old Man said:

To get rid of any digits after the comma you can always use floor.

Wouldn't round be the better option? Not that it makes that much of a difference...

 

Regarding performance: Is floor, round, ceil or toFixed better?

Share this post


Link to post
Share on other sites
18 minutes ago, 7erra said:

Regarding performance: Is floor, round, ceil or toFixed better?

toFixed. if you want a string.

 

btw format["%1" is nonsense, all that is is str. And toFixed already returns string, so utter nonsense there.

Share this post


Link to post
Share on other sites
11 minutes ago, Dedmen said:

btw format["%1" is nonsense, all that is is str. And toFixed already returns string, so utter nonsense there.

Oh, yeah. Was too focused on the task at hand and didn't double check ^^. I assumed there would be another text going with it like km/h or similar.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×