当前位置:网站首页>数字_获取指定位数的小数
数字_获取指定位数的小数
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
边栏推荐
- C#关于set()和get()方法的理解及使用
- flink reads mongodb data source
- Day14 jenkins deployment
- [BJDCTF2020] EasySearch
- The log causes these pits in the thread block, you have to guard against
- 作业8.4 进程间的通信 管道与信号
- 算法---一和零(Kotlin)
- 为什么刚考完PMP,就开始准备软考了?
- Develop your own node package
- App rapid development and construction experience: the importance of small programs + custom plug-ins
猜你喜欢

App rapid development and construction experience: the importance of small programs + custom plug-ins

The production method of the powered small sailboat is simple, the production method of the electric small sailboat

数字孪生技术在电力系统中的应用现状

什么是ASEMI光伏二极管,光伏二极管的作用

ESP32 485光照度

8.04 Day35-----MVC three-tier architecture

4T硬盘剩余很多提示“No space left on device“磁盘空间不足

Flutter学习5-集成-打包-发布

u-boot debugging and positioning means

The role of DataContext in WPF
随机推荐
u-boot in u-boot, dm-pre-reloc
Cron(Crontab)--use/tutorial/example
关于sklearn库的安装
小程序_动态设置tabBar主题皮肤
C语言-大白话理解原码,反码和补码
[CISCN2019 华东南赛区]Web11
数字孪生技术在电力系统中的应用现状
Four-digit display header design
服务器磁盘阵列
mutillidae download and installation
Use IDEA to connect to TDengine server
概率论的学习和整理8: 几何分布和超几何分布
[极客大挑战 2019]FinalSQL
Redis哨兵模式配置文件详解
dedecms dream weaving tag tag does not support capital letters fix
The production method of the powered small sailboat is simple, the production method of the electric small sailboat
Bytebuffer put flip compact clear method demonstration
[8.3] Code Source - [meow ~ meow ~ meow~] [tree] [and]
MySQL基础(一)---基础认知及操作
1007 Climb Stairs (greedy | C thinking)