Rounding a textNumber

Non-platform specific questions.

Rounding a textNumber

Postby Oman » Wed Jul 11, 2007 2:42 am

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? :?
"Beyond a wholesome discipline, be gentle with yourself." - Max Ehrmann
User avatar
Oman
 
Posts: 268
Joined: Tue Oct 31, 2006 4:00 am
Location: Somewhere out there...
Score: 6 Give a positive score

Postby Sgt. Sparky » Wed Jul 11, 2007 2:49 am

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
Last edited by Sgt. Sparky on Wed Jul 11, 2007 5:12 pm, edited 1 time in total.
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby Oman » Wed Jul 11, 2007 2:55 am

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 :?
"Beyond a wholesome discipline, be gentle with yourself." - Max Ehrmann
User avatar
Oman
 
Posts: 268
Joined: Tue Oct 31, 2006 4:00 am
Location: Somewhere out there...
Score: 6 Give a positive score

Postby Fuzzy » Wed Jul 11, 2007 4:20 am

double num = 12456.4678;
num = (int)(num+1);

try that.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Postby Sgt. Sparky » Wed Jul 11, 2007 5:11 pm

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
Image
Random Links:
viewtopic.php?p=19474#19474
Right now (10/14/2009) I'm working on some C++ projects, but I might be able to help if you have some Game Editor questions. :)
User avatar
Sgt. Sparky
 
Posts: 1850
Joined: Sat Oct 07, 2006 5:28 pm
Location: Somewhere out there, beneath the pale blue sky...
Score: 236 Give a positive score

Postby Oman » Thu Jul 12, 2007 5:33 pm

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
Attachments
wow kill counter.zip
this help you grind on World of Warcraft
(762.71 KiB) Downloaded 99 times
"Beyond a wholesome discipline, be gentle with yourself." - Max Ehrmann
User avatar
Oman
 
Posts: 268
Joined: Tue Oct 31, 2006 4:00 am
Location: Somewhere out there...
Score: 6 Give a positive score

Postby pixelpoop » Thu Jul 12, 2007 6:06 pm

ceil(8.3333333333);
User avatar
pixelpoop
 
Posts: 276
Joined: Tue Aug 29, 2006 9:32 pm
Score: 28 Give a positive score

Postby Oman » Thu Jul 12, 2007 6:22 pm

what? i dont understand your post pixelpoop :?
"Beyond a wholesome discipline, be gentle with yourself." - Max Ehrmann
User avatar
Oman
 
Posts: 268
Joined: Tue Oct 31, 2006 4:00 am
Location: Somewhere out there...
Score: 6 Give a positive score

Postby pixelpoop » Thu Jul 12, 2007 6:36 pm

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);
User avatar
pixelpoop
 
Posts: 276
Joined: Tue Aug 29, 2006 9:32 pm
Score: 28 Give a positive score

Postby Oman » Fri Jul 13, 2007 2:01 am

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 :?
"Beyond a wholesome discipline, be gentle with yourself." - Max Ehrmann
User avatar
Oman
 
Posts: 268
Joined: Tue Oct 31, 2006 4:00 am
Location: Somewhere out there...
Score: 6 Give a positive score

Postby pixelpoop » Fri Jul 13, 2007 2:36 am

I put this on the Draw Actor Script of a Text Actor:

textNumber=ceil(textNumber);

and it round properly.
User avatar
pixelpoop
 
Posts: 276
Joined: Tue Aug 29, 2006 9:32 pm
Score: 28 Give a positive score

Postby Oman » Sat Jul 14, 2007 11:06 pm

oh, tyvm, that really helps when im grinding on WoW now. :)
"Beyond a wholesome discipline, be gentle with yourself." - Max Ehrmann
User avatar
Oman
 
Posts: 268
Joined: Tue Oct 31, 2006 4:00 am
Location: Somewhere out there...
Score: 6 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest