ID:156163
 
How do I round a variable up to the nearest whole number? Thanks
round(var)+1

round rounds it down, hence the plus one.
In response to SadKat Gaming
If you read the DM Reference, it tells you how to make round() round a number to the nearest, like you'd expect. You don't need to add one, just use
round(variable, 1)


If you wanted to round to the nearest even number, you'd use
round(variable, 2)
In response to Kaiochao
Not "you don't need to add 1", but "adding 1 is incorrect", as that would result in getting 5 when you try to round 4 to the nearest whole number.
In response to Garthor
where would i place it

say i have

mob
var
Health = 100
Stat()
stat("Health",Health)
In response to Jamesy577
Right there would be fine.
In response to Garthor
it does seem to work where every i put it in my stats? it keeps saying this var value should not be here
In response to Jamesy577
Please use <"dm"> <"/dm"> tags (without ") to show code.

round is function, so you have to call it as function.
mob
var
Health = 100
Stat()
stat("Health", round(Health, 1))
In response to Ripiz
You can use &lt; and &gt; to say < and > when writing tags to prevent them being interpreted as tags.

For example: <dm></dm>
In response to Jamesy577
I've been away from BYOND for awhile, but "This var value should not be here" doesn't really sound like a specific error. When you're trying to get help for compiler errors or warnings, it's best to type them exactly as you see them rather than putting them into your own words. It'll greatly increase your chances of getting help.

That's not why I'm replying though... I just wanted to add that the current method of rounding health in the Stat() output leaves the possibility of it displaying that the mob has 0 health when in fact they could have as much as 0.49~. This could lead to some awkward moments ("Dude! It says I have 0 health but I'm still alive, why?").

Are you sure that your project requires fractional health stats? Maybe a better alternative would to be find wherever the fraction is coming from and rounding that instead.

This is why I like using an intermediary damage proc rather than allowing stuff such as attack verbs manipulate a mob's HP directly.

In response to Zagreus
the player's being on zero helath will not really matter the next hti will kill them the reson i want to round up is because the hgiher level you get the more health you get and when you die u get haf your full health. i am useing 100 health at the momnet but it will got 2 and 105 next so i just want to stop it going to 52.5 do u get me ?
In response to Jamesy577
Statpanels continuously loop. round() is just a basic mathematical operation and very trivial. However, it is a good practice to reduce the number of proc calls from within your stat outputs as much possible... if you're even going to use them. They are kind of outdated and there are a lot of newer interface controls that can handle most of that stuff better if written right. However, that is beyond the scope of this conversation.

If players only die once in awhile, and that's where the fractional health is coming from. Why not round it there instead of every time the statpanel is updated?

Something along the lines of:
mob/proc/death()
src << "Whoops, you died!"
health = round(maxHealth / 2, 1)


Obviously, the way you handle death is going to be different, but that should give you an example.
In response to Zagreus
that helped a lot
In response to Zagreus
Speaking of new interface controls, we got that new bar control, so why don't people use that more often? They look pretty cool, especially when you arc them.