您现在的位置是:首页 > Javascript
当前栏目
js将小数转为整数的方法
2023-03-15 23:18:52 时间
1、使用“parseInt(小数值)”语句。
document.write(parseInt("10") + " "); document.write(parseInt("10.33") + " "); document.write(parseInt("34 45 66") + " "); document.write(parseInt(" 60 ") + " "); document.write(parseInt("40 years") + " "); document.write(parseInt("He was 40") + " "); document.write(" "); document.write(parseInt("10",10)+ " "); document.write(parseInt("010")+ " "); document.write(parseInt("10",8)+ " "); document.write(parseInt("0x10")+ " "); document.write(parseInt("10",16)+ " ");
2、使用“~~小数值”语句。
var decimal=4; var integer = ~~decimal; // 4 = ~~4.123 console.log(integer);
3、使用“Math.floor(小数值)”语句。
console.log(Math.floor(2.5)); //2 console.log(Math.floor(-2.5)); //-3
4、使用“Math.ceil(小数值)”语句。
console.log(Math.ceil(2.5)); //3 console.log(Math.ceil(-2.5)); //-2
5、使用“Math.round(小数值)”语句。
console.log(Math.round(2.5)); //3 console.log(Math.round(-2.5)); //-2 console.log(Math.round(-2.6)); //-3
以上就是js将小数转为整数的方法,希望对大家有所帮助。更多Javascript学习指路:Javascript
相关文章
- TiDB Binlog 组件正式开源
- 使用Visual Studio Code对Node.js进行断点调试
- 推荐!数据可视化的十种优秀JavaScript图表库
- Node.js在复杂集成场景下占据统治地位的五个理由
- 玩转Node.js单元测试
- Node.js中内存泄漏分析
- Angular对React:一场关于Web开发者支持率的史诗对决
- 热点推荐:什么是后端开发?
- 谈谈Spring boot 启动层面的开发
- 使用NodeJS将文件或图像上传到服务器
- 编写React组件的最佳实践
- JavaScript MV*框架最值得关注的七个亮点
- 前端开发指南:如何利用PHP Cake框架构建应用
- 基于React与Vue后,移动开源项目Weex如何定义未来
- NodeJS和C++之间的类型转换
- jQuery中的常用到的三十九个技巧
- 官宣|Google Developers中国网站发布!
- NodeJS和C++之间的类型转换
- .NET Core首例Office开源跨平台组件(NPOI Core)
- 如何写出漂亮的React组件