当前位置:网站首页>数字_获取指定位数的小数
数字_获取指定位数的小数
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
边栏推荐
- Flutter TapGestureRecognizer 如何工作
- 【学生毕业设计】基于web学生信息管理系统网站的设计与实现(13个页面)
- for..in和for..of的区别
- 虚证、实证如何鉴别?
- Detailed explanation of Mysql's undo log
- Mini Program_Dynamic setting of tabBar theme skin
- Is the NPDP certificate high in gold content?Compared to PMP?
- AUTOCAD——标注关联
- The log causes these pits in the thread block, you have to guard against
- 小程序_动态设置tabBar主题皮肤
猜你喜欢

小程序_动态设置tabBar主题皮肤

Redis哨兵模式配置文件详解

u-boot debugging and positioning means

Application status of digital twin technology in power system
![[SWPU2019]Web1](/img/06/36e69a2d7d5475a6749a7d81edf50f.png)
[SWPU2019]Web1
![[BSidesCF 2019]Kookie](/img/29/19e7c244feb86b37ab32a53aa11f25.png)
[BSidesCF 2019]Kookie

The log causes these pits in the thread block, you have to guard against

How to solve complex distribution and ledger problems?

Visibility of multi-column attribute column elements: display, visibility, opacity, vertical alignment: vertical-align, z-index The larger it is, the more it will be displayed on the upper layer

LeetCode:1403. 非递增顺序的最小子序列【贪心】
随机推荐
Some conventional routines of program development (1)
[MRCTF2020]Ezpop(详解)
使用IDEA连接TDengine服务器
人性的弱点
Flutter学习三-Flutter基本结构和原理
Cron(Crontab)--use/tutorial/example
The solution to the failure to read channel information when dedecms generates a message in the background
Flutter learning 5-integration-packaging-publish
Day019 方法重写与相关类的介绍
社区分享|腾讯海外游戏基于JumpServer构建游戏安全运营能力
Cron(Crontab)--使用/教程/实例
[BJDCTF2020] EasySearch
In the hot summer, teach you to use Xiaomi smart home accessories + Raspberry Pi 4 to connect to Apple HomeKit
小程序_动态设置tabBar主题皮肤
bytebuffer use demo
[8.3] Code Source - [meow ~ meow ~ meow~] [tree] [and]
Mysql's redo log detailed explanation
【cesium】加载并定位 3D Tileset
overloaded operator
write the story about us