Coyote Graphics Routines

Date: Fri Mar 27 12:14:20 2015

single page | use frames     summary     class     fields     routine details     file attributes


top cgNumber_Formatter


result = cgNumber_Formatter(number [, DECIMALS=integer])

This is a utility routine format a number into a string. It is used primarily for formatting numbers that will appear in text widgets in widget programs.

Return value

A string with the formatted number or numbers is returned.


number in required

The number to be turned into a string. May be any data type except complex, double complex, pointer or object. May be an array of numbers.


DECIMALS in optional type=integer default=2

Set this keyword to the number of decimal places to be included to the right of the decimal point in floats and doubles. Set to 2 by default. In numbers with absolute values between 0 and 1, the number of decimals is equivalent to the number of significant digits. See the example below.


Here is how to use this program:

IDL> array = [45.123456, -30.123456, !Values.F_Nan, !Values.F_Infinity, $ 0.00123456, -0.00123456, 0.0123456, 0.123456, 1.234567] IDL> FOR j=0,N_Elements(array)-1 DO Print, Number_Formatter(array[j], Decimals=4) 45.1235 -30.1235 NaN Inf 0.001235 -0.001235 0.01235 0.1235 1.2346

Author information



David W. Fanning 1645 Sheely Drive Fort Collins, CO 80526 USA Phone: 970-221-0438 E-mail: Coyote's Guide to IDL Programming:


Copyright (c) 2012, Fanning Software Consulting, Inc.


Change History:

Written, 8 November 2012 by David W. Fanning from the retired Number_Formatter program. The algorithm I was using for numbers between 0 and 1 used a LT in the Where function to find an index. It appears this should have been a LE, instead. 11 Jan 2013. DWF.

File attributes

Modification date: Fri Mar 27 11:07:38 2015
Lines: 279
Docformat: rst rst