Re: Integer - decimal help [message #67720] |
Tue, 25 August 2009 05:07  |
Jean H.
Messages: 472 Registered: July 2006
|
Senior Member |
|
|
Nusret Sevin� wrote:
> Uh, I see that I made a mistake with my 'for loop'. Now the first
> solution works. Thank you very much Marteen.
>
> Nusret
You don't need a for loop here:
IDL> a = [1.2, 3.4, 5.6]
IDL> b = floor(a)
IDL> c = a-b
IDL> print,b
1 3 5
IDL> print,c
0.200000 0.400000 0.600000
Jean
|
|
|
|
Re: Integer - decimal help [message #67722 is a reply to message #67721] |
Tue, 25 August 2009 03:31   |
Nusret Sevinç
Messages: 8 Registered: March 2009
|
Junior Member |
|
|
On 25 Ağustos, 12:28, Maarten <maarten.sn...@knmi.nl> wrote:
> On Aug 25, 11:14 am, Nusret Sevinç <nusretsev...@gmail.com> wrote:
>
>> I don't know how to read the integer and decimal parts of a number
>> separately . For example:
>
>> I have a number: x=34.75
>
>> I would like to read the integer part and decimal part separately:
>> a=34, b=75(or .75)
>
Thanks for your answer Marteen. But these solutions didn't work, I
think I missed to say that my 'x' number is a float array with size of
1461.
> Many possiblities:
>
> ; read x as float, and peel parts apart:
> x = 34.75
> a = floor(x)
> b = x - a
When I tried this one, it gives both a and b zero.
>
> ; read x as string, and use strsplit:
> x = '34.75'
> parts = strsplit(x, ".", /extract)
> a = long(parts[0])
> b = long(parts[1])
>
> Maarten
When I tried to use this one, I changed my float array 'x' into string
array, and here is the error I got:
IDL> parts=strsplit(nu,".",/extract)
% Compiled module: STRSPLIT.
% STRTOK: Expression must be a scalar or 1 element array in this
context: STRINGIN.
% Error occurred at: STRSPLIT 32 /usr/local/rsi/idl_6.3/lib/
strsplit.pro
% $MAIN$
Is there any other way for arrays?
Thanks in advance,
Nusret
|
|
|
|
Re: Integer - decimal help [message #67863 is a reply to message #67720] |
Tue, 25 August 2009 08:24  |
Nusret Sevinç
Messages: 8 Registered: March 2009
|
Junior Member |
|
|
Thanks for your answer Jean, but the for loop I mentioned is a part of
my program and I have to use that solution inside the for loop. At my
first trial, I used that solution outside the for loop and I got both
a and b zero.
Nusret
On 25 Ağustos, 15:07, "Jean H." <jghas...@DELTHIS.ucalgary.ANDTHIS.ca>
wrote:
> Nusret Sevinç wrote:
>> Uh, I see that I made a mistake with my 'for loop'. Now the first
>> solution works. Thank you very much Marteen.
>
>> Nusret
>
> You don't need a for loop here:
>
> IDL> a = [1.2, 3.4, 5.6]
> IDL> b = floor(a)
> IDL> c = a-b
> IDL> print,b
> 1 3 5
> IDL> print,c
> 0.200000 0.400000 0.600000
>
> Jean
|
|
|