[NXC] floor function not working!!!!

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
nxtboyiii
Posts: 366
Joined: 02 Oct 2010, 07:08
Location: Everywhere

Re: [NXC] floor function not working!!!!

Post by nxtboyiii »

what round() function???
And I am using floor because I want it to round to the floor! Not just to nearest integer, but to floor because,lets say, 0.75 has to be 0, not 1, and the floor of 0.75 is 0, not 1.
Thanks, and have a nice day,
nxtboy III

programnxt.com
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: [NXC] floor function not working!!!!

Post by HaWe »

it's because you wrote something about "rounding", not about fractional cut. The term "rounding" means always up or down to the nearest integer, "floor" doesn't round but cuts off the frac part.
nxtboyiii wrote:EDIT: Is there a round function?(round to the nearest tenth, hundredth,etc)
If not, can someone show me how?
I think it was simply a misunderstanding of what you actually want or need.
nxtboyiii
Posts: 366
Joined: 02 Oct 2010, 07:08
Location: Everywhere

Re: [NXC] floor function not working!!!!

Post by nxtboyiii »

Yes. About that. I asked for a round function so when I use floor I can round the integer to the nearest tenth because of floating-point arithmetics.
Thanks, and have a nice day,
nxtboy III

programnxt.com
HaWe
Posts: 2500
Joined: 04 Nov 2014, 19:00

Re: [NXC] floor function not working!!!!

Post by HaWe »

and do you want to round the float or truncate to 1 decimal fixed point and cut off the rest?
1.111 => 1.1 (is trivial)
but:
8.888 => 8.8 or 8.9?
nxtboyiii
Posts: 366
Joined: 02 Oct 2010, 07:08
Location: Everywhere

Re: [NXC] floor function not working!!!!

Post by nxtboyiii »

I want to round I guess.
Thanks, and have a nice day,
nxtboy III

programnxt.com
nxtboyiii
Posts: 366
Joined: 02 Oct 2010, 07:08
Location: Everywhere

Re: [NXC] floor function not working!!!!

Post by nxtboyiii »

I got it to work!!
I just did what linusa said:

Code: Select all

int xx;
float yy;

xx++;
yy=xx/10;
It didn't get messed up!!
Thanks doc-helmut and linusa!
Thanks, and have a nice day,
nxtboy III

programnxt.com
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 0 guests