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

Home » Public Forums » archive » Re: significant figures function?
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: significant figures function? [message #23889 is a reply to message #23884] Mon, 26 February 2001 15:44 Go to previous messageGo to previous message
Ben Tupper is currently offline  Ben Tupper
Messages: 186
Registered: August 1999
Senior Member
You try the following.

;------start
;+
; NAME:
; ROUNDPV
;
; PURPOSE:
; This function returns a rounded value to a specified place value for
Integer, Long, Float, And
; Double precision values.
;
; CATEGORY:
; Miscellaneous, Math
;
; CALLING SEQUENCE:
; Result = RoundPV(Value, PlaceValue)
;
;
; INPUTS:
; Value A scalar or vector of type integer, long integer, float or double
precisions.
; PlaceValue An integer specifying the plave value to round toward.
Positive and negative values
; are permitted.
;
; OPTIONAL INPUTS:
; None
;
; KEYWORD PARAMETERS:
; None
;
; OUTPUTS:
; This function returns the rounded value to the spcified place value.
;
; OPTIONAL OUTPUTS:
; None
;
; COMMON BLOCKS:
; None.
;
; SIDE EFFECTS:
; None known.
;
; RESTRICTIONS:
; None known.
;
; EXAMPLE:
; X = 321.489
; For i = -2, 2 Do Print, RoundPV(X, i)
; 321.480
; 321.400
; 321.000
; 320.000
; 300.000
;
; Specifying a negative place value for an integer or long type data value
has no effect. For example
; X = 321L
; For i = -2, 2 Do Print, RoundPV(X, i)
; 321
; 321
; 321
; 320
; 300
;
; MODIFICATION HISTORY:
; Written by: Ben Tupper 30 SEP 1999
; email pemaquidriver@tidewater.net
; tel: (207) 563 - 1048
; 248 Lower Round Pond Road
; POB 106
; Bristol, ME 04539-0106
;
; 6 FEB 2000 Dropped call to home grown TYPE function in favor of SIZE
function
; with STRUCTURE keyword set.
;
;-


FUNCTION RoundPV, X, PV

If N_elements(PV) EQ 0 Then PV = 0
Sz = Size(X, /Str)

Case Sz.Type of

2: X2 = Fix(Float(Long(Float(X)*10.^(-PV)))*10.^PV)
3: X2 = Long(Float(Long(FLoat(X)*10.^(-PV)))*10.^PV)
4: X2 = Float(Long(X*10.^(-PV)))*10.^PV
5: X2 = Double(Long(X*10.d^(-PV)))*10.d^PV

Else:

EndCase

Return, X2

END


;------finish

Med Bennett wrote:

> Has anyone written a function that returns the input value or array with
> a specified number of significant digits? I have lloked at the various
> IDL libraries on the web but did not come up with what I'm after.
> Thanks in advance for any pointers -

--
Ben Tupper
248 Lower Round Pond Road
POB 106
Bristol, ME 04539

Tel: (207) 563-1048
Email: PemaquidRiver@tidewater.net
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Running IDL from cron
Next Topic: IDL programmers required

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

Current Time: Fri Oct 10 15:08:03 PDT 2025

Total time taken to generate the page: 2.15638 seconds