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

Home » Public Forums » archive » Re: How to eliminate trailing zeros in a string?
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: How to eliminate trailing zeros in a string? [message #33803 is a reply to message #33802] Fri, 24 January 2003 15:05 Go to previous messageGo to previous message
James Kuyper is currently offline  James Kuyper
Messages: 425
Registered: March 2000
Senior Member
David Fanning wrote:
>
> David Fanning (david@dfanning.com) writes:
>
>> K Banerjee (kbanerjee@ucwphilly.rr.com) writes:
>>
>>> Say I have the string "20.304000". How can I eliminate the last 3
>>> zeros?
>>
>> Oh, man, this is going to get me banished from the IDL
>> Expert Programmers Association, but what about this
>> little function:
>>
>> ;***********************************************************
>> FUNCTION StripZeros, str
>>
>> IF N_Elements(str) EQ 0 THEN $
>> theString = '20.304000' ELSE $
>> theString = str
>>
>> char = (Reverse(Byte(theString)))[0]
>> IF char NE 48 THEN RETURN, theString ELSE BEGIN
>> WHILE char EQ 48 DO BEGIN
>> theString = StrMid(theString, 0, StrLen(theString)-1)
>> char = (Reverse(Byte(theString)))[0]
>> ENDWHILE
>> ENDELSE
>> RETURN, theString
>> END
>> ;***********************************************************
>>
>> Run it like this:
>>
>> IDL> Print, StripZeros('20.304000')
>> 20.304
>>
>> I'm not claiming elegant here, but it took me 3 minutes, tops!
>> I'm *sure* I could make it shorter if I had more time. :-)
>
> Alright, I've thought about it a little bit. How about this:
>
> IDL> str = '20.304000'
> IDL> str = String(str, Format='(F6.3)')
> IDL> Print, str
> 20.304

I'd assume from the title that he wants to remove ALL of the trailing
zeros, no matter how many or how few they are.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: IDLgrWindow, IDLgrVolume and alpha channel
Next Topic: MOUSE (WHEEL) BUTTON NON-STOP SCROLLING IN IDL 5.6

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

Current Time: Sat Oct 11 08:40:21 PDT 2025

Total time taken to generate the page: 1.09483 seconds