PDA

View Full Version : round function



hcrisp
09-22-2010, 03:46 PM
Is there a function in PV-WAVE which can round to a specified number of decimal values? Preferably it would return the same datatype as the input and not use string formatting.

rwagner
09-26-2010, 08:01 AM
I don't know of a function off the top of my head, but it would be easy to make one:

function round, x, ths
;x is the number to be rounded
;ths is the place to round to...
; if ths = 10 then x will be rounded to the tenths place
y = long((double(x) * ths + 0.5)/ths)
s = size(x)if s(1) eq 4 then y = float(y)
if s(1) eq 5 then y = double(y)
return, y
end