round - changeable?

You must understand the Game Editor concepts, before post here.

round - changeable?

Postby Superbeni » Sun Feb 28, 2010 5:50 pm

Is it possible to change the numbers of a rounded number?
I would need a number rounded to one decimal number:
1.333333 -> 1.3
0.666666 -> 0.6

Is there any (easy) way to do this?
User avatar
Superbeni
 
Posts: 130
Joined: Sun Aug 02, 2009 1:23 pm
Location: Vienna, Austria
Score: 31 Give a positive score

Re: round - changeable?

Postby Bee-Ant » Sun Feb 28, 2010 6:52 pm

Code: Select all
integer=round(decimal);
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: round - changeable?

Postby Superbeni » Sat Mar 06, 2010 9:46 am

I didn´t get it. :?
What should I write instead of decimal? or should I write decimal?
Integer is the variable?

Could you maybe write an example? (not a demo)

Sorry for this late answer, I didn´t had very much time. :?
User avatar
Superbeni
 
Posts: 130
Joined: Sun Aug 02, 2009 1:23 pm
Location: Vienna, Austria
Score: 31 Give a positive score

Re: round - changeable?

Postby Superbeni » Tue Mar 09, 2010 3:52 pm

Could anyone help, please? :D
User avatar
Superbeni
 
Posts: 130
Joined: Sun Aug 02, 2009 1:23 pm
Location: Vienna, Austria
Score: 31 Give a positive score

Re: round - changeable?

Postby DST » Tue Mar 09, 2010 8:50 pm

Code: Select all
float roundNumber(float k, int places){
int i;
for(i=1; i<=places; i++){     //inflate the number
k*=10;
}
k=round(k);                       //round
for(i=1; i<=places; i++){     
k/=10;                               //deflate the number
}
return k;
}


Inflate, round, deflate.
It's easier to be clever than it is to be kind.
http://www.lostsynapse.com
http://www.dstgames.com
User avatar
DST
 
Posts: 1117
Joined: Sun Apr 15, 2007 5:36 pm
Location: 20 minutes into the future
Score: 151 Give a positive score

Re: round - changeable?

Postby Superbeni » Wed Mar 10, 2010 3:07 pm

A bit longer but I understood it. :mrgreen:
thanks
User avatar
Superbeni
 
Posts: 130
Joined: Sun Aug 02, 2009 1:23 pm
Location: Vienna, Austria
Score: 31 Give a positive score

Re: round - changeable?

Postby thunderios » Tue Mar 16, 2010 3:10 pm

Code: Select all
float roundNumber(float k, int places){
    int i;
    k*=pow(10, i);
    k=round(k);                       //round
   
    k/=pow(10,i);                               //deflate the number
    return k;
    }
Might be simpler.
thunderios
 
Posts: 87
Joined: Thu Jan 31, 2008 1:18 pm
Score: 1 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron