Hello Friends, The reasom for the unexpected behaviour seems to have been found and the problem seems to have been solved. Thanks to the _trace() function.
Actually, the title bar was showing values to two decimal digits, whereas the actual values were having higher precision. So what was visible in title bar as 5240.65 could actally be 5240.6471; and RoundDn_TickSize could rightly round the value down to 5240.60. Though will further stress test the values, problem seems to have been solved to great extent. Thanks to all for the inputs. With Regards Sanjiv Bansal --- In [email protected], "sanjiv" <sumanga...@...> wrote: > > Hello Friends, > > I need to ROUND UP or DOWN some values based on TickSize. Sometimes I need to > round UP and sometimes round Down. Based upon some postings of the Group, I > wrote following functions for the purpose. MOST of the time the results are > on expected line. However on some RARE occasions RoundUp_TickSize is > returning lower value. Sometimes RoundUp_TickSize as well as RoundDn_TickSize > are modifying already round values. Further prec(ARRAY, precision ) function > is giving errors if my functions are called inside a loop. > > It will be nice if you can please guide me my errors. > > With Regards > > Sanjiv Bansal > > =================== > > TickSize = 0.05; > > function Round2TickSize( aValue ) > { > TickInv = 1 / TickSize; > return ( round( aValue * TickInv ) / TickInv ); > } > > function RoundUp_TickSize( aValue ) > { > TickInv = 1 / TickSize; > return( (ceil( Prec(aValue,2) * TickInv )) / TickInv); > } > > function RoundDn_TickSize( aValue ) > { > TickInv = 1 / TickSize; > return( (floor( Prec(aValue,2) * TickInv )) / TickInv); > } >
