标签:doctype size body math 实现 str bsp int git
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>转换数字单位KB、MB、GB、TB</title> </head> <body> <script type="text/javascript"> const formatFileSize = size => { const scale = 1000 const digitList = [‘KB‘, ‘MB‘, ‘GB‘, ‘TB‘] let _integer = size/scale //最小单位kb let digit = 0 while(_integer > scale) { _integer = Math.round(_integer/scale) digit++ } return `${_integer}${digitList[digit]}` } document.write(formatFileSize(2003)); </script> </body> </html>
标签:doctype size body math 实现 str bsp int git
原文地址:https://www.cnblogs.com/caoxueying2018/p/11203339.html