Actual numbers to the human readable values
问题 I have data in bytes. I need to draw this values as human readable labels on a chart (like 2.5KB, 14MB etc.) and need to help with function (input data - actual value, output - human readable string). I did funcion like this, but I 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