JS indexOf(),split(),substring(),substr(),Math.ceil(),Math.floor(),Math.round()的内容

indexOf():

var mystr="Hello WorHld!"

括号内若只有一个参数,代表要查找的字符;例:document.write(mystr.indexOf("H"));

括号内若有两个参数,前一个代表要查找的字符,后一个代表从哪个位置开始查找;例:document.write(mystr.indexOf("H",7));

若要查找的字符没有,则返回-1

split():切割符

var mystr="86-010-85468578";

括号内若填 "-" ,则表示在"-"切割,结果为:86,010,85468578

括号内若填 "-" ,2 ,则表示在"-"切割,切两段,结果为:86,010

括号内若填 "" ,则每个字符都会被分割,结果为:8,6,-,0,1,0,-,8,5,4,6,8,5,7,8

括号内若填 "",3 ,则前三个字符都会被分割,结果为:8,6,-

substring():提取字符串

var mystr="Hello World!"

当substring()的括号内填 一个(数字)参数 a,则表示返回从a(包括a)开始一直到  结尾.length-1  的字符

当substring()的括号内填 两个(数字)参数  a,b ,则表示返回从a(包括a)开始一直到b的字符

substr():提取指定数目

var mystr="Hello World!";

当括号内填一个(数字)参数a时,表示从a(不包括a)开始一直到  结尾

当括号内填两个(数字)参数 a,b 时,表示从a开始,到后面的 b 个字符,例:document.write(mystr.substr(0,5));——输出:Hello

var mystr="Hello World!";

-1是倒数第一个字符(!),-2是倒数第二个字符(d!),依此类推

Math.ceil():向上取整数

例:document.write(Math.ceil(-9.9));——输出:-9

document.write(Math.ceil(-0.1));——输出:0

Math.floor():想下取整

例:document.write(Math.floor(-9.9));——输出:-10

document.write(Math.floor(-0.1));——输出:-1

Math.round():四舍五入

例:document.write(Math.round(-9.9));——输出:-10

document.write(Math.round(-0.1));——输出:0

原文地址:https://www.cnblogs.com/chenyuan7/p/9164946.html

时间: 2024-07-31 23:50:55

JS indexOf(),split(),substring(),substr(),Math.ceil(),Math.floor(),Math.round()的内容的相关文章

Javascript Math ceil()、floor()、round()三个函数的区别

Round是四舍五入的...Ceiling是向上取整..float是向下取整  下面来介绍将小数值舍入为整数的几个方法:Math.ceil().Math.floor()和Math.round(). 这三个方法分别遵循下列舍入规则:◎Math.ceil()执行向上舍入,即它总是将数值向上舍入为最接近的整数:◎Math.floor()执行向下舍入,即它总是将数值向下舍入为最接近的整数:◎Math.round()执行标准舍入,即它总是将数值四舍五入为最接近的整数(这也是我们在数学课上学到的舍入规则).

Jquery Math ceil()、floor()、round()比较与用法

Math.ceil():向上取值 如:Math.ceil(2.1) --  结果为  3 Math.ceil(-2.1)  -- 结果为-2 结论:正入 负舍 Math.floor(): 先下取值 入: Math.ceil(2.1) --  结果为  2 Math.ceil(-2.1)  -- 结果为-3 结论:和ceil()结论相反. 正舍 负入 Math.round:四舍五入 Math.round(2.1) --  结果为  2 Math.round(2.6) --  结果为  3 Math

python中的math.ceil(x)和math.floor(x)

一 math.ceil(x) import math 1.当x为正数时,只要x的小数部分>0就+1 x=5.01 print(math.ceil(x)) #6 x=5.9 print(maht.ceil(x)) #6 2.当x为负数时,舍去小数部分 x=-5.9 print(math.ceil(x)) #-5 x=-5.01 print(math.ceil(x)) #-5 二.math.floor(x) 1.当x为正数时,舍去小数部分 x=5.9 print(math.floor(x)) #5

php取整函数ceil,floor,round,intval函数的区别

开发过程中,遇到数据处理取整的时候,你会用哪个呢,小涛来介绍一下:PHP取整函数有ceil,floor,round,intval,下面详细介绍一下: 1.ceil — 进一法取整说明float ceil ( float $value )返回不小于 value 的下一个整数,value 如果有小数部分则进一位.ceil() 返回的类型仍然是 float,因为 float 值的范围通常比 integer 要大.ceil() 例子 <?php echo ceil(4.3); // 5 echo cei

[转]PHP取整函数:ceil,floor,round,intval的区别详细解析

我们经常用到的PHP取整函数,主要是:ceil,floor,round,intval. 1.ceil -- 进一法取整 说明float ceil ( float value ) 返回不小于 value 的下一个整数,value 如果有小数部分则进一位.ceil() 返回的类型仍然是 float,因为 float 值的范围通常比 integer 要大. PHP取整函数例子 1. ceil() 例子 echo ceil(4.3); // 5 echo ceil(9.999); // 10 2.flo

java中常用到的math方法(Math.PI、Math.random()、Math.abs(double)、Math.floor(double)、Math.ceil(double)、Math.round(double))

public class MathDemo { public static void main(String args[]){ /** * abs求绝对值 */ System.out.println(Math.abs(-10.4));    //10.4 System.out.println(Math.abs(10.1));     //10.1 /** * ceil天花板的意思,就是返回大的值,注意一些特殊值 */ System.out.println(Math.ceil(-10.1));  

JavaScript里Math对象的ceil()、floor()、round()方法的区别

ceil(x) 官方含义:对一个数进行上舍入.理解:ceiling为天花板的意思,意译为向上取整.即取得大于于等于x的最大整数. floor(x) 官方含义:对一个数进行下舍入.理解:floor为地板的意思,意译为向下取整.即取得小于等于x的最大整数. round() 官方含义: 把一个数四舍五入为最接近的整数.理解:传统意义的四舍五入. 例1: var a = 3.5;document.write(Math.floor(a)) ;document.write(Math.ceil(a)) ;do

JS 中的substring ,substr ,slice,split,join

substr with different arguments passed in: str.substring(startNum,stopNum ); str.slice(startNum,stopNum ); str.substr(startNum,length ); substring vs slice start = stop ,return ‘ ‘; the same. start or stop bigger than str.length, it will make the big

javascript中slice(),splice(),split(),substring(),substr()使用方法

1.slice(): Array和String对象都有 在Array中  slice(i,[j]) i为开始截取的索引值,负数代表从末尾算起的索引值,-1为倒数第一个元素j为结束的索引值,缺省时则获取从i到末尾的所有元素 参数返回:返回索引值从i到j的数组,原数组不改变 在String中 slice(i,[j]) 参数说明:i为开始截取的索引值,负数代表从末尾算起的索引值,-1为倒数第一个字符j为结束的索引值,缺省时则获取从i到末尾的所有字符 2.splice() 存在Array中     方法

slice(),splice(),split(),substring(),substr()使用法

1.slice(): Array和String对象都有 在Array中  slice(i,[j]) i为开始截取的索引值,负数代表从末尾算起的索引值,-1为倒数第一个元素j为结束的索引值,缺省时则获取从i到末尾的所有元素 参数返回:返回索引值从i到j的数组,原数组不改变 在String中 slice(i,[j]) 参数说明:i为开始截取的索引值,负数代表从末尾算起的索引值,-1为倒数第一个字符j为结束的索引值,缺省时则获取从i到末尾的所有字符 2.splice() 存在Array中     方法