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

Home » Public Forums » archive » Re: Excluding Decimal Places in the Values of a Variable
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Excluding Decimal Places in the Values of a Variable [message #83237 is a reply to message #83236] Thu, 14 February 2013 12:55 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Lisa08 writes:

>
> Hi everyone,
>
> I have a question that I think should be very simple to answer but I can't seem to find a solution for it.
>
> I am trying to chop off the last two decimal places for the values of a variable. The values for my variable have 5 decimal places and I want to trim it down to 3. For example, let's say my variable is:
>
> x=[[1.35679, 2.65487], [3.65789, 4.56455]]
>
> So I want to exclude the last two decimal places and have it be:
>
> x=[[1.356, 2.654], [3.657, 4.564]]
>
>
> Now, I know how to do this using a "PRINT" command as below but I don't know how to tell IDL to save the output that was printed out to a variable.
>
>
> IDL> print, x, FORMAT='(F8.3)'
> 1.357
> 2.655
> 3.658
>
> Also, Is there a way to make it "not round up"? I have found a routine that does what I want, excludes the final two decimal places and doesn't round up, but the problem with it is that it converts the values to a string to do this and then I can't seem to convert them back to floats as it gives me the following error:
>
> Type Conversion error: Unable to convert given STRING to Float
>
> The routine I found online to do this is called DECIMALS.pro and is available here:
>
> https://people.ok.ubc.ca/erosolo/idl/lib/decimals.pro

I would do it this way:

IDL> x=[[1.35679, 2.65487], [3.65789, 4.56455]]
IDL> x = Fix(x*1000)/1000.

Cheers,

David

--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: cghistoplot: getting histdata values without any plotting?
Next Topic: Re: differences among map_proj_image, map_image and map_patch

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

Current Time: Fri Oct 10 06:57:04 PDT 2025

Total time taken to generate the page: 2.40037 seconds