当前位置:网站首页>number_gets the specified number of decimals
number_gets the specified number of decimals
2022-08-05 05:03:00 【good girl @@@】
保留小数_四舍五入
NumberThere is a method on the prototype chaintoFixed
[1]语法
number.toFixed([num])number为Number类型的数据
num为可选参数:表示要保留几位小数
- If notnum,默认不保留小数
- Rounding is done during rounding of decimals;
[2]返回值
The return value is the specified number of decimal places字符串;
[3]举例说明
11.123456.toFixed() // '11'
11.123456.toFixed(3) // '11.123'
11.123456.toFixed(4) // '11.1235'
保留小数_向下取整
[1]语法
Math.floor([num])
- floor方法的作用是获取numthe integer value and return it(Decrease the value directly to truncate the value before the decimal point)
- num为可选参数
- 不传,返回结果为NaN
- If it is not passedNumber类型,This method will convert the data to Numbertype to get an integer;
[2]返回值
返回Number类型的整数
[3]举例说明
// [1]获取整数
Math.floor(11.123456) // 11
// [2]获取3decimal integer
Math.floor(11.123456*1000)/1000 // 11.123
// [3]获取4Integer with decimal places
Math.floor(11.123456*10000)/10000 // 11.1234
保留小数_向上取整
[1]语法
Math.ceil([num])
- ceil方法的作用是获取numthe integer value and return it(向上取值-Add as long as there are decimals1)
- num为可选参数
- 不传,返回结果为NaN
- If it is not passedNumber类型,This method will convert the data to Numbertype to get an integer;
[2]返回值
返回Number类型的整数
[3]举例说明
// [1]获取整数
Math.ceil(11.123456) // 12
// [2]获取3decimal integer
Math.ceil(11.123456*1000)/1000 // 11.124
// [3]获取4Integer with decimal places
Math.ceil(11.123456*10000)/10000 // 11.1235
// [4]获取6Integer with decimal places
Math.ceil(11.123456*10000)/10000 // 11.123456
边栏推荐
- [SWPU2019]Web1
- Four-digit display header design
- 1007 Climb Stairs (greedy | C thinking)
- Cron(Crontab)--use/tutorial/example
- 【cesium】Load and locate 3D Tileset
- [8.1] Code Source - [The Second Largest Number Sum] [Stone Game III] [Balanced Binary Tree]
- The solution to the failure to read channel information when dedecms generates a message in the background
- 8.04 Day35-----MVC三层架构
- 使用IDEA连接TDengine服务器
- 1068 Find More Coins
猜你喜欢
虚证、实证如何鉴别?

Develop your own node package
![[8.1] Code Source - [The Second Largest Number Sum] [Stone Game III] [Balanced Binary Tree]](/img/f3/0d92e22a424206241f4e1640f1bf6b.png)
[8.1] Code Source - [The Second Largest Number Sum] [Stone Game III] [Balanced Binary Tree]

【学生毕业设计】基于web学生信息管理系统网站的设计与实现(13个页面)

Detailed explanation of Mysql's undo log
![[Surveying] Quick Summary - Excerpt from Gaoshu Gang](/img/35/e5c5349b8d4ccf9203c432a9aaee7b.png)
[Surveying] Quick Summary - Excerpt from Gaoshu Gang
How to identify false evidence and evidence?

C++ core programming

Error creating bean with name ‘configDataContextRefresher‘ defined in class path resource

结构光三维重建(一)条纹结构光三维重建
随机推荐
In the hot summer, teach you to use Xiaomi smart home accessories + Raspberry Pi 4 to connect to Apple HomeKit
[Geek Challenge 2019]FinalSQL
App rapid development and construction experience: the importance of small programs + custom plug-ins
MySQL基础(一)---基础认知及操作
【学生毕业设计】基于web学生信息管理系统网站的设计与实现(13个页面)
1007 Climb Stairs (greedy | C thinking)
jvm 三 之堆与栈
[8.2] Code Source - [Currency System] [Coins] [New Year's Questions (Data Enhanced Edition)] [Three Stages]
一篇博客通关Redis技术栈
Analyses the mainstream across technology solutions
Flutter 父子组件如何都能收到点击事件
Cron(Crontab)--use/tutorial/example
mutillidae download and installation
Flutter learning 5-integration-packaging-publish
dedecms error The each() function is deprecated
【informix】解决启动报错大全,以及解决办法
人性的弱点
App快速开发建设心得:小程序+自定义插件的重要性
Understanding and use of C# on set() and get() methods
[8.3] Code Source - [meow ~ meow ~ meow~] [tree] [and]