Re: float-to-string

From: Dave Allured <dave.allured_at_nyahnyahspammersnyahnyah>
Date: Thu, 20 Jul 2006 13:00:24 -0600

Use the sprintf function:

sprintf gives you better control over number of decimal places and other
number formatting issues. If the "minimum field width" in the %
operator is zero or null, then I think you will get a variable length
string result, with no leading spaces on each number.

Regarding "length of 6", your purpose and formatting assumptions to do
this are unclear. Your dimsizes (stringtochar ()) method will probably
do what you want. But you might consider using a numeric bracket test
instead; it may be more reliable for your purpose. HTH.

--Dave Allured
CIRES Climate Diagnostics Center
NOAA Earth Systems Research Laboratory, Physical Sciences Division

Kyle Wilcox wrote:
> Is there an easy way to do a "floattostring" conversion? Right now I
> just let NCL do it automatically and get the coarse warning message each
> time. Does that slow down the script at all?
> Example: 'cutdata' is array of floats, and I need to process only those
> with the length of '6'.
> if (dimsizes(stringtochar(cutdata(newdata))) - 1 .eq. 6) then
> ; do something
> else
> ; don't do something
> * Excited next version of NCL for 'strlen' *
> Thanks.

ncl-talk mailing list
Received on Thu Jul 20 2006 - 13:00:24 MDT

This archive was generated by hypermail 2.2.0 : Thu Jul 20 2006 - 14:36:52 MDT