please suggest how to reliably round down or perhaps chop

 

using normalizedouble on eg: 0.667 to 2 places gives 0.67

is there a simple way to always ensure that round down occurs?

other than writing a function with value and decimal places actuals eg; fred(double d,int digits)

if used 'fred' maybe is like this:

a = fred(0.667,3); and fred does: {return(NormalizeDouble(d-(5.0/MathPow(10,digits+1)),digits));}


just seems that is an uneducated solving which maths mind could put me right... - can simpler method be done?

thanks

(100th edit...)

blow seem ok but must be another way

Print("fred(0.667,2) -> ",fred(0.667,2));

Print("fred(0.67,1) -> ",fred(0.67,1));

Print("fred(0.660,2) -> ",fred(0.660,2));

Print("fred(0.661,2) -> ",fred(0.661,2));

Print("fred(0.669,2) -> ",fred(0.669,2));


_test GBPUSD,M5: fred(0.669,2) -> 0.66

_test GBPUSD,M5: fred(0.661,2) -> 0.66

_test GBPUSD,M5: fred(0.660,2) -> 0.66

_test GBPUSD,M5: fred(0.67,1) -> 0.6

_test GBPUSD,M5: fred(0.667,2) -> 0.66

 
multiply by 100,mathfloor, divide by 100.. should work, or am i wrong?
 
enotrek:
multiply by 100,mathfloor, divide by 100.. should work, or am i wrong?
2010.08.13 20:04:53 _test EURUSD,M15: d = 0.667*100.0; --> d = 66.7
2010.08.13 20:04:53 _test EURUSD,M15: d = MathFloor(d); --> d = 66
2010.08.13 20:04:53 _test EURUSD,M15: d /= 100.0; --> d = 0.66


yes, is ok. This seems to be chop. Maybe I make generic so could pass in 10,100,1000,...

and looks cleaner etc. Feeble minds need clarity - lol

cheers

Reason: