comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Integer - decimal help
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Integer - decimal help [message #67720] Tue, 25 August 2009 05:07 Go to next message
Jean H. is currently offline  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 #67721 is a reply to message #67720] Tue, 25 August 2009 03:37 Go to previous messageGo to next message
Nusret Sevinç is currently offline  Nusret Sevinç
Messages: 8
Registered: March 2009
Junior Member
Uh, I see that I made a mistake with my 'for loop'. Now the first
solution works. Thank you very much Marteen.

Nusret
Re: Integer - decimal help [message #67722 is a reply to message #67721] Tue, 25 August 2009 03:31 Go to previous messageGo to next message
Nusret Sevinç is currently offline  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 #67723 is a reply to message #67722] Tue, 25 August 2009 02:28 Go to previous messageGo to next message
Maarten[1] is currently offline  Maarten[1]
Messages: 176
Registered: November 2005
Senior Member
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)

Many possiblities:

; read x as float, and peel parts apart:
x = 34.75
a = floor(x)
b = x - a

; read x as string, and use strsplit:
x = '34.75'
parts = strsplit(x, ".", /extract)
a = long(parts[0])
b = long(parts[1])

Maarten
Re: Integer - decimal help [message #67863 is a reply to message #67720] Tue, 25 August 2009 08:24 Go to previous message
Nusret Sevinç is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Speed-up of code
Next Topic: Digits in IDL

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:38:42 PDT 2025

Total time taken to generate the page: 0.00539 seconds