1、四舍五入

(2.678).toFixed(2) // 2.68

2、不需要四舍五入

(parseInt(2.678*100)/100.0).toFixed(2) // 2.67

3、字节单位转换

function convertByte(bytesNum) {

            var unit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB', 'BB', 'NB', 'DB'],
count = 0; if (bytesNum <= 0) {
return bytesNum;
}
if (bytesNum < 1024) {
return bytesNum + unit[0];
} while (count<unit.length) {
bytesNum = bytesNum / 1024;
if (bytesNum < 1024) {
console.log(bytesNum);
bytesNum = bytesNum.toFixed(1) == parseInt(bytesNum.toFixed(1)) ? bytesNum.toFixed(0) : bytesNum.toFixed(1);//如果有小数则保留一位小数
return bytesNum + unit[count];
}
count++;
}
}

最新文章

  1. angular2 service component
  2. C语言模块化编译介绍
  3. 【译】微型ORM:PetaPoco【不完整的翻译】
  4. Winform窗体
  5. SpringMVC视图
  6. 浙江大学 pat 题解---58
  7. Ajax应用-定义一套自己的Ajax框架
  8. 创建自己的composer包
  9. JavaScript学习历程03
  10. sort、sorted高级排序-Python3.7 And 算法&lt;七&gt;
  11. 【翻译】 View Frustum Culling --1 View Frustum’s Shape
  12. MFC命名规范
  13. 计算机从加电到系统(Linux)启动完成
  14. mysql补充(4)数据完整性
  15. crontab 执行脚本,报错/home/scripts/eyeMonitor.sh: line 8: node: command not found
  16. Visual Studio win平台 AI环境搭建
  17. python中的关键字符
  18. linux下查看doc在线帮助文件
  19. Web 服务器配置
  20. 解决ios下audio不能正常播放的问题

热门文章

  1. KendoUI系列:AutoComplete
  2. js中关于value的一个小知识点(value既是属性也是变量)
  3. JAVA--网络编程(UDP)
  4. NYOJ 1023 还是回文(DP,花最少费用形成回文串)
  5. poj 2777(线段树的节点更新策略)
  6. PHP获取图片宽度高度、大小尺寸、图片类型、用于布局的img属性
  7. Spark入门实战系列--6.SparkSQL(下)--Spark实战应用
  8. Struts2 源码分析——前言
  9. Android Studio导入项目非常慢的解决办法
  10. 图论 ---- spfa + 链式向前星 ---- poj 3268 : Silver Cow Party