Page 1 of 1

Rounding a textNumber

PostPosted: Wed Jul 11, 2007 2:42 am
by Oman
Hey everyone,

I have a game, that eventually calculates a textNumber based on data that you entered.

However when you enter the data, it sometimes comes to 12357.3758549.

It would very very helpful for the user, if it would automaticly round to the next HIGHEST number. EX. 1256.298909 (should now equal) 1257

Can i do this? :?

PostPosted: Wed Jul 11, 2007 2:49 am
by Sgt. Sparky
just use,
Code: Select all
char temp[2][255];
float num = textNumber;
sprintf(temp[0], "%f", num);
textNumber = round(textNumber);
sprintf(temp[1], "%f", num);
if(strcmp(temp[0], temp[1]) != 0 && temp[1] < temp[0])textNumber++;

:D

PostPosted: Wed Jul 11, 2007 2:55 am
by Oman
yes, but i want it to round UP to the next HIGHEST number, no matter what the first number is. Does it do that?

doesent seem like it to me :?

PostPosted: Wed Jul 11, 2007 4:20 am
by Fuzzy
double num = 12456.4678;
num = (int)(num+1);

try that.

PostPosted: Wed Jul 11, 2007 5:11 pm
by Sgt. Sparky
Oman wrote:yes, but i want it to round UP to the next HIGHEST number, no matter what the first number is. Does it do that?

doesent seem like it to me :?

yes. :D

PostPosted: Thu Jul 12, 2007 5:33 pm
by Oman
Ok, Everyone, here is my game. If you Play WoW DOWNLOAD it!

Now, if you download it enter this.

total xp needed = 2000
average xp gained per kill = 120
xp i already have = 1000

then click the equals sign

now, my game will minus xp have from xp needed (that equals 1000).
Then divides the difference by average xp gained. The answer without rounding is 8.33333333 (and so on). I want the answer to round UP to 9. With Sparkies code it rounds down to 8. That is Not What I Want. AHHH, this is driving me CRAZY :x

PostPosted: Thu Jul 12, 2007 6:06 pm
by pixelpoop
ceil(8.3333333333);

PostPosted: Thu Jul 12, 2007 6:22 pm
by Oman
what? i dont understand your post pixelpoop :?

PostPosted: Thu Jul 12, 2007 6:36 pm
by pixelpoop
use "ceil" to round a number up to the nearest whole number. You wanted 8.333333333 rounded to 9. This does that: ceil(8.3333333333);

PostPosted: Fri Jul 13, 2007 2:01 am
by Oman
ok, but i never know what the number will equal, and when i put

Code: Select all
ceil(textNumber);


on my textNumber actor it doesn't work :?

PostPosted: Fri Jul 13, 2007 2:36 am
by pixelpoop
I put this on the Draw Actor Script of a Text Actor:

textNumber=ceil(textNumber);

and it round properly.

PostPosted: Sat Jul 14, 2007 11:06 pm
by Oman
oh, tyvm, that really helps when im grinding on WoW now. :)