Home › Forums › kdb+ › Decimal Places by Condition › Re: Decimal Places by Condition
-
q)show val:.01 .0125 .01234568 .9999 .008 0.01 0.0125 0.01234568 0.9999 0.008 q).001*floor .5+1000*val 0.01 0.013 0.012 1 0.008
More generally, as a function which takes number of decimal places as its left argument:
q){%[;s]floor .5+y*s:10 xexp x}[3]val 0.01 0.013 0.012 1 0.008
Slightly less obviously you can elide
floor .5+
with a faster Cast:q){%[;s]"i"$y*s:10 xexp x}[3]val 0.01 0.013 0.012 1 0.008