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

Home » Public Forums » archive » print a la C
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: print a la C [message #9243 is a reply to message #9059] Wed, 04 June 1997 00:00 Go to previous message
R. Bauer is currently offline  R. Bauer
Messages: 137
Registered: November 1996
Senior Member
Andrea Spinelli wrote:
>
> Hi,
>
> does anybody know whether there is a freely available somewhere a
> function for printing floats in a way similar to the %g
> argument of printf? E.g.:
>
> printf("%g\n",0.02); [C]
> results in
> 0.02
>
> print, 0.01 [IDL]
> 0.0100000

Hi Andrea,

I can share one of my functions with you.
num_dec is written by Ray Sterner and you can get it from his library.

http://fermi.jhuapl.edu/res/





;Copyright R.Bauer
;Institut fuer stratosphaerische Chemie


function number_format,number,format=format,help=help

IF keyword_set(help) THEN BEGIN
print,'(number_forms) no_string=number_forms(number)'
print,'use format=format to get the Format code'

return,-1
ENDIF




ab = strtrim(string(number),2)


dp = strtrim(string(num_dec(number)),2)
length = strtrim(string(strpos(ab,'.')+1+long(dp)),2)


form = "(f"+length+"."+dp+")"


IF keyword_set(format) THEN BEGIN
return,form
ENDIF

return,string(format=form,number)



END



--
R.Bauer

Institut fuer Stratosphaerische Chemie (ICG-1)
Forschungszentrum Juelich
email: R.Bauer@fz-juelich.de
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: Re: Beta just expired, anyone got the new one yet?
Next Topic: Re: IDL FAQ - better format

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

Current Time: Wed Oct 08 16:06:56 PDT 2025

Total time taken to generate the page: 0.00439 seconds