当前位置:网站首页>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
边栏推荐
- Talk about 20 common problems in data governance
- 特征预处理
- 作业8.4 进程间的通信 管道与信号
- Is the NPDP certificate high in gold content?Compared to PMP?
- 基于Web的商城后台管理系统的设计与实现
- Day019 方法重写与相关类的介绍
- upload upload pictures to Tencent cloud, how to upload pictures
- The log causes these pits in the thread block, you have to guard against
- Machine Learning Overview
- 大学物理---质点运动学
猜你喜欢
随机推荐
Flutter学习4-基本UI组件
Cryptography Series: PEM and PKCS7, PKCS8, PKCS12
请写出SparkSQL语句
mutillidae download and installation
How can Flutter parent and child components receive click events
Learning and finishing of probability theory 8: Geometric and hypergeometric distributions
LAB Semaphore Implementation Details
开发属于自己的node包
『递归』递归概念与典型实例
u-boot调试定位手段
Shell(4) Conditional Control Statement
什么是ASEMI光伏二极管,光伏二极管的作用
8.04 Day35-----MVC three-tier architecture
【cesium】Load and locate 3D Tileset
dedecms报错The each() function is deprecated
upload上传图片到腾讯云,如何上传图片
dedecms后台生成提示读取频道信息失败的解决方法
[Surveying] Quick Summary - Excerpt from Gaoshu Gang
基于Web的商城后台管理系统的设计与实现
Qixi Festival earn badges









