Taking a floating point number, I would like to round down, depending upon a user defined 'bin' size. The bin size therefore will change depending upon user preference. For example, the bin sizes may be 0.5, 0.1, 1 or even 0.01.
My aim is to determine which bin a floating point number will fall into. As an example:
a 0.1 bin size:
2348.285 will fall into a 2348.2 bin 238.592 will fall into a 238.5 bin a 0.5 bin size:
2348.285 will fall into a 2348.0 bin 238.592 will fall into a 238.5 bin a 0.01 bin size:
2348.285 will fall into a 2348.28 bin 238.592 will fall into a 238.59 bin a 1 bin size:
2348.285 will fall into a 2348 bin 238.592 will fall into a 238 bin I have looked into rounding in Perl for example, the floor(), sprintf() and also substr() methods, however, none of them do quite want I want to do, or rather, I can't make them do what I want. What neat code will dynamically change the floor value that the floating point number will round down to given the user-defined bin size?