Math ceil()、floor()、round()方法

Math.Round()函数说明 Math.Round()并不是严格意义上的是四舍五入函数。它默认的执行的是“银行家舍入”算法,即四舍六入五取偶。概括为:四舍六入五考虑、五后非零就进一,五后皆零看奇偶,五前为偶应舍去、五前为奇要进一。 阅读详情

Math ceil()、floor()、round()方法

 

Math.ceil()

 
功能:对一个数进行上取整。

语法:Math.ceil(x)

参数:

x:一个数值。
返回值:返回大于或等于x,并且与之最接近的整数。

注:如果x是正数,则把小数“入”;如果x是负数,则把小数“舍”。

例:

<script type="text/javascript">
document.write( Math.ceil(1.2)+", "+Math.ceil(1.8)+", "+Math.ceil(-1.2)+", "+Math.ceil(-1.8) );
</script>

输出结果为:

2, 2, -1, -1
 

 

Math.floor()

 
功能:对一个数进行下取整。

语法:Math.floor(x)

参数:

x:一个数值。
返回值:返回小于或等于x,并且与之最接近的整数。

注:如果x是正数,则把小数“舍”;如果x是负数,则把小数“入”。

例:

<script type="text/javascript">
document.write( Math.floor(1.2)+", "+Math.floor(1.8)+", "+Math.floor(-1.2)+", "+Math.floor(-1.8) );
</script>

输出结果为:

1, 1, -2, -2
 

 

Math.round()

 
功能:四舍五入取整。

语法:Math.round(x)

参数:

x:一个数值。
返回值:与x最接近的整数。

例:

<script type="text/javascript">
document.write( Math.round(1.2)+", "+Math.round(1.8)+", "+Math.round(-1.2)+", "+Math.round(-1.8) );
</script>

输出结果为:

1, 2, -1, -2
 


本文来自优快云博客,转载请标明出处:http://blog.youkuaiyun.com/xiaxiaorui2003/archive/2009/12/10/4980076.aspx

Math的几个方法Math.round()、Math.ceil()、Math.floor()和Math.abs()记录一下 Math.round() 就是数学中的四舍五入,举例: System.out.println("Math.round(1.2)="+Math.round(1.2)); System.out.println("Math.round(1.5)="+Math.round(1.5)); System.out.println("Math.round(1.7)="+Math.round(1.7)... 阅读详情

相关推荐

[语义分割]SPP、空洞卷积与ASPP总结

ASPP全称:Atrous Spatial Pyramid Pooling,中文可以理解为空洞空间卷积池化金字塔或者多孔空间金字塔池化。在这其中,要理解两个概念:一个是SPP,池化金字塔结构或者叫空间金字塔池化层,都是一个东西;另一个是Atrous,空洞卷积,两个加在一起就是ASPP。 首先说一下SPP:Spatial Pyramid Pooling。这个结构出自于论文《Spatial Pyramid Pooling in Deep Convolutional Networks for Visual Re

lipengfei0427的博客 2万+

Math.round(),Math.ceil(),Math.floor()的区别

1、Math.round() “四舍五入”,该函数返回的是一个四舍五入后的的整数 double d = 3.1415926; double d2 = 18.58; double d3 = -15.23; double d4 = -16.85; long round1 = Math.round(d); //...

zuihongyan518的博客 22万+

海康Camera MVS Linux SDK二次开发封装ROS packge过程记录(c++)

https://www.hikrobotics.com/machinevision/service/download?module=0

weixin_41965898的博客 2万+

Math.round()方法

Math.round()方法即为我们常说的“四舍五入”方法,但用起来不注意的话就会犯错。 注意Math.round(-1.5),也就是-1.5“四舍五入”的结果并不是-2,而是-1。 这是为什么呢?

本人整理的笔记与总结,涉及Android,Java,React,设计模式,算法等,愿对大家有帮助 9万+

Ubuntu Server 22.04.5系统安装教程

该教程主要是演示在服务器上安装Ubuntu server 22.04系统的详细步骤,主要包含,安装系统前的准备(镜像的下载,启动盘的制作),安装系统时的语言选择,网络设置,切换镜像源(可根据实际需求来配置,本文使用清华镜像源),手动分区,用户设置,ssh服务安装等。以上就是关于Ubuntu Server 22.04系统安装的详细过程。

逆水行舟,不进则退。 7761

新手避坑指南:用镭神C32和KVH 1750 IMU做标定,为什么直接上lidar_align会失败?

本文详细解析了使用镭神C32激光雷达和KVH 1750 IMU进行标定时常见的失败原因及解决方案。从IMU的微分传感器特性到Lidar-IMU标定的数学本质,再到可行的标定方案和实操注意事项,帮助新手避开认知陷阱,掌握正确的标定方法。

weixin_30162121的博客 327

math.ceil()的用法

math.ceil(x) # 返回不小于x的最接近的整数 math.ceil(0.33) Out[3]: 1 math.ceil(0.93) Out[4]: 1

qq_35037684的博客 1万+

投稿前利用GPT-5.5给论文做一次深度校对,投稿命中率翻倍!

3)一致性:请对比摘要的结论与正文(如果我也提供了正文),确保完全一致。请严格检查结果部分,确保客观性:1)纯粹性检查:标出所有包含“为什么”(解释)或“这意味着什么”(暗示)的主观语句,这些应移至讨论部分。请你帮我评估讨论部分的深度:1)解释与对比:检查每一项主要结果是否都解释了原因,并引用了前人研究进行对比(一致或相悖)。我见过太多人把校对理解为检查错别字了,实际上,校对要看的远不止这个,像逻辑是否连贯、术语是否前后一致、图表有没有被正确引用等等的这些细节,往往决定了文章是秒被拒,还是能顺利进入外审。

智能AI让学术科研更容易 412

Parseint()、Math.round()、Math.floor()、Math.ceil()四种取整方法的区别

parseInt() 该方法取整是把小数点后面小数去掉,只保留整数部分。parseInt作用: 1.函数可解析一个字符串,并返回一个整数。console.log(parseInt(19.11));//返回19 2.舍去小数点后的数字不进行四舍五入。 console.log(parseInt(19.99));//19 3.可以转换进制。 console.log(parseI...

weixin_44600235的博客 1696

QGis二次开发 —— 1、win10/win11搭建Vs2017-QGis3.40.12环境(附Vs2017环境效果,附全部问题解决方法)(附:Qt助手加入QGis接口说明文档)

QGis二次开发 —— 1、Windows10搭建Vs2017-QGis环境(附Vs2017环境效果)(附:Qt助手加入QGisA接口说明文档)

1362

Langchain cannot connect with Azure SQL Database

Langchain 无法连接到 Azure SQL 数据库

suiusoar 633

Math工具类的ceil()、floor()、round()方法源码阅读

以double数据类型为例:0表示这个浮点数为正数1表示这个浮点数为负数计算一个double数值类型的数据data = (-1)^S * M * 2^E在计算机中存储时,阶码采用移码-1的方式存储,尾数只存储小数部分移码就是对补码的符号位进行取反。 Math.ceil(double)里面调用了StrictMath.ceil(double);Math.flooor(double)里面调用了StrictMath.floor(double)。在 StrictMath类中的ceil(double)和floor(do

qq_56460466的博客 856

SolidWorks速成教程P1——简介及基础操作

SolidWorks教程P1——简介及基础操作

嵌入式阿齐Archie 2万+

parseInt()、Math.round()、Math.floor()、Math.ceil()四种取整方法的区别

在最近的js练习中经常会用到随机数的使用,而使用随机数时大部分会对齐进行取整。   parseInt() 该方法取整是把小数点后面小数去掉,只保留整数部分。如果要取整的数为正时,类似Math.floor();为负时,类似Math.ceil()   Math.round() 四舍五入取整   Math.floor() 向下取整  如Math.floor(1.8) 返回 1;Math.floor

锦瑟无端五十弦 5971

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

java Math.round()、Math.ceil()、Math.floor()取整方法的区别

Math.round() “四舍五入”,就看小数点后第一位的值小数点后第一位5小数点后第一位=5 Math.ceil():(ceil:天花板)向上取整,及小数部分,直接不管,整数部分加1 Math.floor():(floor:地板)向下取整,小数点后的,直接丢掉 【注】 Math.floor()容易出现精度问题,举个最简单例子:对小数 8.54 保留两位小数(虽然它已经保留了 2 位小数):Math.floor(8.54*100)/100 // 输出结果为 8.53, 注意...

dayuiicghaid的博客 718

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

js Math对象的round(),ceil(),floor()方法

1、Math.round() 功能:四舍五入取整。 语法:Math.round(x) 参数: x:一个浮点数。 返回值:与x最接近的整数。 注:当出现两个最接近的整数,将返回最大的那个整数。 示例: Math.round(1.3);//1 Math.round(1.5);//2 Math.round(1.7);//2 Math.round(-1.3);//-1 Math.round(-1.5);//-1 Math.round(-1.7);//-2 2、Math.floo...

旭东怪的博客 1791

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

Math ceil(),floor(),round()方法的使用

floor 返回不大于的最大整数 round 则是4舍5入的计算,入的时候是到大于它的整数(当-1.5时可见,四舍五入后得到的结果不是我们期待的,解决办法是先对他取绝对值,然后在用round方法) round方法,它表示“四舍五入”,算法为Math.floor(x+0.5),即将原来的数字加上0.5后再向下取整,所以,Math.round(11.5)的结果为12,Math.round(-11

road_16的专栏 893

Android中Math类Math.floor()、Math.round()及Math.ceil()等方法的使用

1、Math.floor()先看定义:/** * Returns the double conversion of the most positive (closest to positive * infinity) integer value less than or equal to the argument. * <p> * Special cases: * <ul> * <li>

Just do it 1万+

android 向下取整函数,Android中Math类Math.floor()、Math.round()及Math.ceil()等方法的使用...

1、Math.floor()先看定义:/*** Returns the double conversion of the most positive (closest to positive* infinity) integer value less than or equal to the argument.* * Special cases:* * {@code floor(+0.0) = +...

weixin_35772595的博客 2532

Math类中round(), ceil(), floor()方法

1.round() 简单讲,四舍五入。但是要注意对于负数的情况 Math.round(-5.6) = - 6 Math.round(-5.4) = - 5 Math.round(5.6) = 6 Math.round(5.4) = 5 2.ceil() 3.floor()

Willow_zhu的博客 596

JS中Math对象pow(),abs(),ceil(),floor(),round()等常用方法

关于JS中Math对象常用的方法 JavaScript Math对象 Math对象多用来执行常见的算术方法。 Math.Pow(x,y) pow方法用于返回x的y次幂的值 x:底数 y:指数 console.log(Math.pow(2,4)); //输出16 Math.abs() abs方法用于返回一个绝对值 返回类型:number,如果不是数字返回NaN,0返回null。 console.l...

Peggy0829的博客 1258

JavaScript Math对象 ceil()、floor()、round()方法

Math.ceil() 功能:对一个数进行上取整。 语法:Math.ceil(x) 参数: x:一个数值。 返回值:返回大于或等于x,并且与之最接近的整数。 注:如果x是正数,则把小数“入”;如果x是负数,则把小数“舍”。 例: document.write( Math.ceil(1.2)+", "+Math.ceil(1.8)+", "+Math.ceil(-1.2)+"

wangjuan_01的专栏 2万+

Math对象的ceil()、floor()、round()方法

ceil:向上取整,返回值float类型。 floor:向下取整,返回值float类型。 round:四舍五入,返回值int类型。 关于ceil和floor,想象一条y轴,不论负数正数,都向y轴的上或下方向取整。而四舍五入的原理是,把当前数加0.5,再向下取整。如Math.round(-1.5)的值是-1 ...

MOWRONG的博客 516

js 整数处理方法Math.ceil()、 Math.floor()、 Math.round()

最近遇到关于js的整数截取问题,记录一下。 js内置的Math模块有三种处理规则:Math.ceil()、Math.floor()、Math.round() Math.ceil() 指的是向上取整: Math.ceil(1.2) ## 结果为 2 Math.ceil(1.5) ## 结果也为 2 Math.ceil(1.8) ## 结果也为 2 ## 总而言之,...

Ray_Huang 456
上一篇: 金融工具知识
下一篇: 监控和剖析数据库操作 -- P6Spy、SQL Profiler、IronTrack SQL(网络
小瑞
博客等级 码龄19年 240粉丝 274原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值