当前位置:网站首页>数字_获取指定位数的小数
数字_获取指定位数的小数
2022-08-05 04:52:00 【乖女子@@@】
保留小数_四舍五入
Number原型链上存在一个方法toFixed
[1]语法
number.toFixed([num])number为Number类型的数据
num为可选参数:表示要保留几位小数
- 若是不传num,默认不保留小数
- 保留小数过程中会四舍五入;
[2]返回值
返回值为指定小数位数的字符串;
[3]举例说明
11.123456.toFixed() // '11'
11.123456.toFixed(3) // '11.123'
11.123456.toFixed(4) // '11.1235'
保留小数_向下取整
[1]语法
Math.floor([num])
- floor方法的作用是获取num的整数值并返回(向下取值直接截取小数点前的值)
- num为可选参数
- 不传,返回结果为NaN
- 若是传递非Number类型,该方法会默认将数据转化为Number类型再获取整数;
[2]返回值
返回Number类型的整数
[3]举例说明
// [1]获取整数
Math.floor(11.123456) // 11
// [2]获取3位小数整数
Math.floor(11.123456*1000)/1000 // 11.123
// [3]获取4位小数的整数
Math.floor(11.123456*10000)/10000 // 11.1234
保留小数_向上取整
[1]语法
Math.ceil([num])
- ceil方法的作用是获取num的整数值并返回(向上取值-只要有小数就加1)
- num为可选参数
- 不传,返回结果为NaN
- 若是传递非Number类型,该方法会默认将数据转化为Number类型再获取整数;
[2]返回值
返回Number类型的整数
[3]举例说明
// [1]获取整数
Math.ceil(11.123456) // 12
// [2]获取3位小数整数
Math.ceil(11.123456*1000)/1000 // 11.124
// [3]获取4位小数的整数
Math.ceil(11.123456*10000)/10000 // 11.1235
// [4]获取6位小数的整数
Math.ceil(11.123456*10000)/10000 // 11.123456
边栏推荐
- The first performance test practice, there are "100 million" a little nervous
- 淘宝账号如何快速提升到更高等级
- 什么是ASEMI光伏二极管,光伏二极管的作用
- [极客大挑战 2019]FinalSQL
- Day019 Method overriding and introduction of related classes
- C+ +核心编程
- In the WebView page of the UI automation test App, the processing method when the search bar has no search button
- [SWPU2019]Web1
- [BJDCTF2020]EasySearch
- how to measure distance from point to face in creo
猜你喜欢
随机推荐
特征预处理
The production method of the powered small sailboat is simple, the production method of the electric small sailboat
Flutter学习5-集成-打包-发布
software management rpm
工业级远距离无线传输装置的功能有哪些?
虚证、实证如何鉴别?
Flutter学习三-Flutter基本结构和原理
基于Web的商城后台管理系统的设计与实现
七夕节赚徽章拉
In the hot summer, teach you to use Xiaomi smart home accessories + Raspberry Pi 4 to connect to Apple HomeKit
C#关于set()和get()方法的理解及使用
一篇博客通关Redis技术栈
How to identify false evidence and evidence?
Bytebuffer put flip compact clear method demonstration
作业8.4 进程间的通信 管道与信号
for..in和for..of的区别
Flutter学习4-基本UI组件
什么是ASEMI光伏二极管,光伏二极管的作用
The role of DataContext in WPF
【informix】解决启动报错大全,以及解决办法


![[极客大挑战 2019]FinalSQL](/img/e4/0c8225ef7c5e7e5bdbaac2ef6fc867.png)






