Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

javascript - Actual numbers to the human readable values -


i have data in bytes. need draw values human readable labels on chart (like 2.5kb, 14mb etc.) , need function (input data - actual value, output - human readable string).

i did funcion this, want more elegant realization

function tickformatter(value, type) {      var suffix = (type == "bytes") ? ['b', 'kb', 'mb', 'gb'] : ['', 'k', 'm', 'g']      if(value > (1024 * 1024 * 1024 * 1024)) {         return (value / (1024 * 1024 * 1024 * 1024)).tofixed(2) + suffix[3]     } else if(value > (1024 * 1024 * 1024)) {         return (value / (1024 * 1024 * 1024)).tofixed(2) + suffix[2]     } else if (value > (1024 * 1024)) {         return (value / (1024 * 1024)).tofixed(2) + suffix[1]     } else {         return value.tofixed(2) + suffix[0]     } } 

i love implementation: clear , compact:

function readablizebytes(bytes) {     var s = ['bytes', 'kb', 'mb', 'gb', 'tb', 'pb'];     var e = math.floor(math.log(bytes) / math.log(1024));     return (bytes / math.pow(1024, e)).tofixed(2) + " " + s[e]; } 

usage:

readablizebytes(10000000) "9.54 mb" 

i don't take credit of this.


Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -