ZizZazZuz
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 2743 |
|
|
| 25 Jan 2012 09:50 AM |
| How do I tell wether or not a number is an integer or a number? Integer being a subset of number. |
|
|
| Report Abuse |
|
grimm343
|
  |
| Joined: 18 Sep 2008 |
| Total Posts: 2796 |
|
|
| 25 Jan 2012 10:02 AM |
Ignoring your explanation..
function check(n) if n == (math.floor(n) and math.abs(n)) then print(n.." is an integer and a whole number") elseif n == math.floor(n) then print(n.." is an integer.") end end
|
|
|
| Report Abuse |
|
su8
|
  |
| Joined: 06 Mar 2009 |
| Total Posts: 6334 |
|
|
| 25 Jan 2012 10:19 AM |
function check(n) if n==math.floor(n) then print("int") else print("number") end end
|
|
|
| Report Abuse |
|
grimm343
|
  |
| Joined: 18 Sep 2008 |
| Total Posts: 2796 |
|
|
| 25 Jan 2012 10:50 AM |
Whole numbers: 0,1,2,3,4,5,6... Integers: ...-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6...
All whole numbers are integers.
Checking for an integer: num == math.floor(num)
Checking for a whole number (also an integer): num == (math.abs(num) and math.floor(num)) |
|
|
| Report Abuse |
|