NCL Home >
Documentation >
Functions >
General applied math
					decimalPlaces
Truncates or rounds to the number of decimal places specified.
Prototype
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"  ; This library is automatically loaded
                                                             ; from NCL V6.2.0 onward.
                                                             ; No need for user to explicitly load.
	function decimalPlaces (
		x           : numeric,  
		nplaces [1] : integer,  
		round   [1] : logical   
	)
	return_val  :  numeric
Arguments
xAn array of any dimensionality.
nplacesA scalar integer equal to the number of places to truncate.
roundA scalar logical. True = round, False = truncate.
Description
This function runcates or rounds to the number of decimal places specified. Note: decimalPlaces rounds up to the maximum absolute number. See Example 1.
Note: If it is for printing or placing within a string or plot title, it may be better to use the sprintf function.
See Also
Examples
Example 1: This demonstrates the NCL 6.4.0 behavior.
     
     x   = 12.345678
     xT  = decimalPlaces(x ,2,True)  ; 12.35 
     xF  = decimalPlaces(x ,2,False) ; 12.34
     xx  = (/ x, -x /)
     xxT = decimalPlaces(xx,2,True)  ; (/12.35, -12.35/) 
     xxF = decimalPlaces(xx,2,False) ; (/12.34, -12.34/)