当前位置:网站首页>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
边栏推荐
- Mini Program_Dynamic setting of tabBar theme skin
- The first performance test practice, there are "100 million" a little nervous
- [Geek Challenge 2019]FinalSQL
- AUTOCAD - dimension association
- LeetCode:1403. 非递增顺序的最小子序列【贪心】
- flink reads mongodb data source
- [8.2] Code Source - [Currency System] [Coins] [New Year's Questions (Data Enhanced Edition)] [Three Stages]
- [Surveying] Quick Summary - Excerpt from Gaoshu Gang
- Mvi架构浅析
- 【学习笔记之菜Dog学C】动态内存管理之经典笔试题
猜你喜欢
机器学习概述
Use IDEA to connect to TDengine server
C++ core programming
Flutter学习三-Flutter基本结构和原理
jvm 三 之堆与栈
逆向理论知识4
Qt制作18帧丘比特表白意中人、是你的丘比特嘛!!!
[cesium] 3D Tileset model is loaded and associated with the model tree
Detailed explanation of each module of ansible
upload upload pictures to Tencent cloud, how to upload pictures
随机推荐
Cryptography Series: PEM and PKCS7, PKCS8, PKCS12
NPDP证书含金量高吗?跟PMP相比?
什么是ASEMI光伏二极管,光伏二极管的作用
虚证、实证如何鉴别?
ESP32 485光照度
dedecms报错The each() function is deprecated
Excel画图
span标签和p标签的区别
雷克萨斯lm的安全性到底体现在哪里?一起来看看吧
Redis哨兵模式配置文件详解
Cron(Crontab)--use/tutorial/example
类的底层机制
upload上传图片到腾讯云,如何上传图片
Flutter Learning 4 - Basic UI Components
[8.1] Code Source - [The Second Largest Number Sum] [Stone Game III] [Balanced Binary Tree]
[BJDCTF2020] EasySearch
dedecms织梦tag标签不支持大写字母修复
uboot enable debug printing information
Flutter learning 2-dart learning
【软考 系统架构设计师】软件架构设计③ 特定领域软件架构(DSSA)