javascript - Round to nearest X -


there simple answer question can't seem find it. have number (dollar amount) such 0.34, round nearest x, meaning if x 0.15 want round 0.15, 0.3, 0.45, 0.6, 0.75 or 0.9. example don't want exact numbers, want able make x between 0.01 , 0.5 , number can rounded increment.

this question here rounds nearest 0.25 kind of want buy want generic function rounds numbers decimal portion set fraction.

round nearest .25 javascript

number.prototype.round2dec = function(x){   return /* "this" round nearest x */; }; 

number.prototype.round2dec = function(x){   return (math.round(this * (1/x)) / (1/x)); }; 

from example given, 4 = 1/(0.25), expanded pattern x.

edit - looking through answers, realized have answer there, not expanding prototype - round nearest .25 javascript.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -