Outputting number of decimal places

Post » Sun Nov 18, 2012 10:25 am

Hi everyone,

I've modified the ResourceFurnitureScript in order to chop firewood until my max carry weight. I wanted to display notifications at the top right similar to Firewood Added (2)
using debug.notifications, These are Max Carry Weight, Current Carry Weight, and Remaining Firewood.

Current carry weight is currently in float form, because Skryim rounds the decimal inventory weight, for example 150.32 down to 150 and 150.56 to 151. How can I make my current inventory weight round to two decimal places?

I pulled this from stackoverflow
float val = 37.777779;float rounded_down = floor(val * 100) / 100;   /* Result: 37.77 */float nearest = floor(val * 100 + 0.5) / 100;  /* Result: 37.78 */float rounded_up = ceil(val * 100) / 100;	  /* Result: 37.78 */cout << nearest;
I've tried float nearest it still shows the zeros (150.250000)
float trueInvWeight = Game.GetPlayer().GetActorValue("inventoryweight")float rounded = floor(trueInvWeight * 100 + 0.5) / 100.0debug.Notification("Current Carry Weight " + "(" + rounded + ")")

On the Creation Kit wiki, I've read about the show function and the flag section

It says to use %10.2f to round to two decimals, but I couldn't implement a show message or use it within debug.notification
User avatar
Loane
 
Posts: 3411
Joined: Wed Apr 04, 2007 6:35 am

Post » Sun Nov 18, 2012 8:42 am

Well, papyrus apparently has no string manipulation without SKSE. With SKSE you can easily do it like this if you import StringUtil (I didn't test it):
float trueInvWeight = Game.GetPlayer().GetActorValue("inventoryweight")float rounded = floor(trueInvWeight * 100 + 0.5) / 100.0  string out = Substring( rounded as string, 0, Find(rounded as string, ".", 0)+2 )debug.notification(out)
With "2" being the number of decimal places.

Without SKSE, you can do this:
float trueInvWeight = Game.GetPlayer().GetActorValue("inventoryweight")float rounded = floor(trueInvWeight * 100 + 0.5) / 100.0int whole = floor(rounded)int dec = floor((rounded - whole) * 100 + 0.5)debug.notification(whole+"."+dec)

You can also do it with a message like you said. But I assumed you wanted it to be a notification so that it's at the top left of the screen. If you want to do it with a message, just create the message in the creation kit and make it a property of the script, then follow the instructions on the wiki page for message.show.
User avatar
His Bella
 
Posts: 3428
Joined: Wed Apr 25, 2007 5:57 am

Post » Sun Nov 18, 2012 6:35 pm

thanks seventyfour, the non SKSE code did the trick. :foodndrink:
User avatar
Imy Davies
 
Posts: 3479
Joined: Fri Jul 14, 2006 6:42 pm


Return to V - Skyrim