| View previous topic :: View next topic |
| Author |
Message |
Rasmus Newbie

Joined: 10 Dec 2004 Posts: 4 Location: DK
|
Posted: Fri Dec 10, 2004 7:46 am Post subject: Identify Natural Numbers? |
|
|
Hallo,
I'm trying to make Calc identify the values which belongs to the natural numbers (i.e. no 1,2,3... no decimals or fractions.)
In column A I have the values of x from 1 to 1000 and column 2 I have the value of f(a).
So what I would like would be something like this
A B C
1 3,2 0 (false)
2 4 1 (True)
...
Hope somebody can help me.
Thanks in advance,
Rasmus
btw: I did try a search but didn't find anything.
edit: can one somehow sort all data depending on the value? In Excel one can add drop down boxes to sort. What I'd like to do, would be to sort so all the trues (1 I guess) are in the top. _________________ Music is Life... the Rest is Details. |
|
| Back to top |
|
 |
David Super User


Joined: 24 Oct 2003 Posts: 5668 Location: Canada
|
Posted: Fri Dec 10, 2004 8:41 pm Post subject: Re: Identify Natural Numbers? |
|
|
| Rasmus wrote: | Hallo,
I'm trying to make Calc identify the values which belongs to the natural numbers (i.e. no 1,2,3... no decimals or fractions.)
In column A I have the values of x from 1 to 1000 and column 2 I have the value of f(a).
So what I would like would be something like this
A B C
1 3,2 0 (false)
2 4 1 (True)
...
Hope somebody can help me.
Thanks in advance,
Rasmus
btw: I did try a search but didn't find anything.
edit: can one somehow sort all data depending on the value? In Excel one can add drop down boxes to sort. What I'd like to do, would be to sort so all the trues (1 I guess) are in the top. |
Use the INT() function. Suppose you have 12.356 in A1. In B1 put this:
=If(INT(A1) = A1;TRUE;FALSE)
This puts 1 if an integer [or natural number], or 0 if not.
You can vary that according to your specific need, checking for negatives if necessary.
David. |
|
| Back to top |
|
 |
Rasmus Newbie

Joined: 10 Dec 2004 Posts: 4 Location: DK
|
Posted: Sat Dec 11, 2004 4:19 am Post subject: |
|
|
Thanks it worked out, Dave, after a bit of tweaking -- apparently OpenOffice DK doesn't use English commands so I had to figure out what the different functions were called in the Danish version. The funny thing is, that the documentation still is in English, and therefor have the English commands listed However the function window (ctrl + F2) is quite useful.
I also figured the search thing out. _________________ Music is Life... the Rest is Details. |
|
| Back to top |
|
 |
Ed Super User

Joined: 28 May 2003 Posts: 1040
|
Posted: Sat Dec 11, 2004 10:20 am Post subject: Re: Identify Natural Numbers? |
|
|
| David wrote: |
This puts 1 if an integer [or natural number], or 0 if not.
|
The function you have described only tells you if the number is an integer, not if it is a natural number. To detect natural numbers, you have to add an extra condition that the number is strictly greater than zero.
The only way I can see of doing this is to use the formula
| Code: | | =AND(IF(INT(A1)=A1);IF(A1>0)) |
BTW the commands are not necessary, since OOo uses these values by default anyway. |
|
| Back to top |
|
 |
David Super User


Joined: 24 Oct 2003 Posts: 5668 Location: Canada
|
Posted: Sat Dec 11, 2004 8:23 pm Post subject: Re: Identify Natural Numbers? |
|
|
| Ed wrote: | | David wrote: |
This puts 1 if an integer [or natural number], or 0 if not.
|
The function you have described only tells you if the number is an integer, not if it is a natural number. To detect natural numbers, you have to add an extra condition that the number is strictly greater than zero.
The only way I can see of doing this is to use the formula
| Code: | | =AND(IF(INT(A1)=A1);IF(A1>0)) |
BTW the commands are not necessary, since OOo uses these values by default anyway. |
You are quite right. Your code is neat and concise and should be used instead, but not all are aware of defaults, which can indeed be useful. I've used the TRUE/FALSE idea elsewhere, such as here, where the sign of E9 is decided on the basis of D9 being a positive or negative sign character. If positive, the first is true, and has a value of 1 with the second, False, a value of 0 ....or vise versa if a negative sign.
=(TRUNC(RAND()*$BK$2)+$BK$3)*(B9+E9*((D9="+")-(D9="-")))*(IF(MID ...etc.
David. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|