Page 1 of 1

Math question?

Posted: Tue Apr 09, 2013 6:16 am
by Ryeath_Greystalk
What is the command to get only the interger part of a number?

I tried e = math.abs(a*.3) but that gives a decimal point.
I tried e = math.int(a*.3) but that gives an error "attempt to call field a nil value"

ow can I get just the whole number of 30% of a and assign it to e.

Thanks.

----------edit ----------
Found it.

math.modf

Looking at the description it returns both the interger and the remainder so what I am doing is

e = math.modf(a*.3)
print e
> 27

If I wanted to use both (I don't in this case but for learning purposes, would it go like this?
e,f = math.modf(a*3)
print e,f
>27 .5

Re: Math question?

Posted: Tue Apr 09, 2013 8:13 am
by alois
Ryeath_Greystalk wrote:What is the command to get only the interger part of a number?

I tried e = math.abs(a*.3) but that gives a decimal point.
I tried e = math.int(a*.3) but that gives an error "attempt to call field a nil value"

ow can I get just the whole number of 30% of a and assign it to e.

Thanks.

----------edit ----------
Found it.

math.modf

Looking at the description it returns both the interger and the remainder so what I am doing is

e = math.modf(a*.3)
print e
> 27

If I wanted to use both (I don't in this case but for learning purposes, would it go like this?
e,f = math.modf(a*3)
print e,f
>27 .5
Also, just to get the integer part: math.floor (and math.ceiling to 'round' up).

alois :)

Re: Math question?

Posted: Tue Apr 09, 2013 8:25 pm
by Ryeath_Greystalk
Thanks for that additional information alois.

I saw the math.floor and math.ceil and for some reason thought they returned the upper and lower end of a range. Don't know where I came up with that crazy idea.