Number questions
Number questions
Hey, been wondering this for some time. How do I compare a number too see if it's decimal or an integer?
Re: Number questions
Code: Select all
if math.floor(number) == number then
-- is integer
else
-- non-integer
end
long as the number is not very large or small.
Re: Number questions
If that's what you want to do, ivan's solution should work just fine. It sounds to me however like something you would never need to do. If you need an integer, but aren't sure it is one, just use math.floor(datNumber) (or math.floor(datNumber + 0.5) if you want to round it).
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
Re: Number questions
You could also check if a number is an integer by doing this:
Code: Select all
function isInteger( x )
return x % 1 == 0
end
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Re: Number questions
Both solutions work for me. Basically I was trying to make this kind of grid:
+1 point for anyone who guesses right what kind of clone I'm making?
Code: Select all
{
{w,w,w,w,w,w,w,w,w}
{w,0,0,0,0,0,0,0,w}
{w,0,i,0,i,0,i,0,w}
{w,0,0,0,0,0,0,0,w}
{w,0,i,0,i,0,i,0,w}
{w,0,0,0,0,0,0,0,w}
{w,0,i,0,i,0,i,0,w}
{w,0,0,0,0,0,0,0,w}
{w,w,w,w,w,w,w,w,w}
} -- i = indestructable
-- w = wall
-- 0 = floor
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Number questions
Just a shot in the darkBindie wrote:+1 point for anyone who guesses right what kind of clone I'm making?
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: Number questions
Bull's eye, +1!
Re: Number questions
Why would you need to know if a number is an integer or not to produce such a grid?
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
Re: Number questions
My best guess is he halfed the x coordinate and checked whether it was integer?T-Bone wrote:Why would you need to know if a number is an integer or not to produce such a grid?
In that case he should've just take the modulo-2:
Code: Select all
if x%2 == 0 then -- x is even end
Re: Number questions
That's right, I found an easier solution though using false and true values.S0lll0s wrote:My best guess is he halfed the x coordinate and checked whether it was integer?
In that case he should've just take the modulo-2:Code: Select all
if x%2 == 0 then -- x is even end
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests