学用 ASP.Net 之 System.Math 类
/* 字段 */
Math.E; //2.71828182845905
Math.PI; //3.14159265358979 /* 静态方法 */
Math.Abs; //绝对值
Math.Acos; //反余弦
Math.Asin; //反正弦
Math.Atan; //反正切
Math.Atan2; //反正切, 两参数
Math.BigMul; //int32 * int32 = int64
Math.Ceiling; //取 >= 的最小整数
Math.Cos; //余弦
Math.Cosh; //双曲余弦
Math.DivRem; //取商和余数
Math.Exp; //求 e 的指定次幂
Math.Floor; //取 <= 的最大整数
Math.IEEERemainder; //求余
Math.Log; //自然对数
Math.Log10; //以 10 为底的对数
Math.Max; //取大
Math.Min; //取小
Math.Pow; //求幂
Math.Round; //就近舍入, 可指定精度
Math.Sign; //取符号, 或返回 -1、0、1
Math.Sin; //正弦
Math.Sinh; //双曲正弦
Math.Sqrt; //平方根
Math.Tan; //正切
Math.Tanh; //双曲正切
Math.Truncate; //取整
练习:
//Truncate()、Floor()、Ceiling()
protected void Button1_Click(object sender, EventArgs e)
{
double n1 = Math.Truncate(Math.PI); // 3 double n2 = Math.Floor(2.5); // 2
double n3 = Math.Floor(-2.5); //-3 double n4 = Math.Ceiling(2.5); // 3
double n5 = Math.Ceiling(-2.5); //-2 TextBox1.Text = string.Concat(n1, "\n", n2, "\n", n3, "\n", n4, "\n", n5);
} //就近舍入(取偶)
protected void Button2_Click(object sender, EventArgs e)
{
double n1 = Math.Round(0.5); // 0
double n2 = Math.Round(1.5); // 2
double n3 = Math.Round(2.5); // 2
double n4 = Math.Round(3.5); // 4
double n5 = Math.Round(-0.5); // 0
double n6 = Math.Round(-1.5); //-2
double n7 = Math.Round(-2.5); //-2
double n8 = Math.Round(-3.5); //-4 TextBox1.Text = string.Concat(n1, "\n", n2, "\n", n3, "\n", n4, "\n", n5, "\n", n6, "\n", n7, "\n", n8);
} //四舍五入
protected void Button3_Click(object sender, EventArgs e)
{
double n1 = Math.Round(0.5, MidpointRounding.AwayFromZero); // 1
double n2 = Math.Round(1.5, MidpointRounding.AwayFromZero); // 2
double n3 = Math.Round(2.5, MidpointRounding.AwayFromZero); // 3
double n4 = Math.Round(3.5, MidpointRounding.AwayFromZero); // 4
double n5 = Math.Round(-0.5, MidpointRounding.AwayFromZero); //-1
double n6 = Math.Round(-1.5, MidpointRounding.AwayFromZero); //-2
double n7 = Math.Round(-2.5, MidpointRounding.AwayFromZero); //-3
double n8 = Math.Round(-3.5, MidpointRounding.AwayFromZero); //-4 TextBox1.Text = string.Concat(n1, "\n", n2, "\n", n3, "\n", n4, "\n", n5, "\n", n6, "\n", n7, "\n", n8);
} //指定小数位数(0..28)的舍入
protected void Button4_Click(object sender, EventArgs e)
{
double n1 = Math.Round(3.126, 2); // 3.13
double n2 = Math.Round(3.124, 2); // 3.12 double n3 = Math.Round(3.125, 2); // 3.12
double n4 = Math.Round(3.135, 2); // 3.14 double n5 = Math.Round(3.125, 2, MidpointRounding.AwayFromZero); // 3.13
double n6 = Math.Round(3.135, 2, MidpointRounding.AwayFromZero); // 3.14 TextBox1.Text = string.Concat(n1, "\n", n2, "\n", n3, "\n", n4, "\n", n5, "\n", n6);
}
学用 ASP.Net 之 System.Math 类的更多相关文章
- 学用 ASP.Net 之 System.Collections.ArrayList 类
ArrayList 是 .Net 的动态数组. 主要成员: /* 静态方法 */ ArrayList.Adapter() //把其他 IList 对象包装为 ArrayList 使用 ArrayLis ...
- 08 正则表达式,Math类,Random,System类,BigInteger,BigDecimal,Date,DateFormat,Calendar
正则表达式: 是指一个用来描述或者匹配一系列符合某个语法规则的字符串的单个字符串.其实就是一种规则.有自己特殊的应用. public class Demo2_Regex { public sta ...
- 基本类型包装类、System类、Math类、Arrays类、大数据运算
1 基本类型包装类 Java中想对8种基本数据类型进行复杂操作很困难. 实际程序界面上用户输入的数据都是以字符串类型进行存储的. 程序开发中,需要把字符串转换成指定的基本数据类型. 1.1基本数据类型 ...
- 正则表达式、Calendar类、SimpleDateFormat类、Date类、BigDecimal类、BigInteger类、System类、Random类、Math类(Java基础知识十四)
1.正则表达式的概述和简单使用 * A:正则表达式(一个字符串,是规则) * 是指一个用来描述或者匹配一系列符合某个语法规则的字符串的单个字符串.其实就是一种规则.有自己特殊的应用. * B: ...
- JAVA学习第四十五课 — 其它对象API(一)System、Runtime、Math类
一.System类 1. static long currentTimeMillis() 返回以毫秒为单位的当前时间. 实际上:当前时间与协调世界时 1970 年 1 月 1 日午夜之间的时间差(以毫 ...
- Java常用类之【Math类、Random类、System类、Runtime类】
一.Math类 Math类 [绝对值]Math.abs();//返回对应类型的绝对值 [最大值和最小值]Math.max(int a, int b) ,Math.min(int a,int b);(其 ...
- java 基本类型包装类,system类,Math类,Assrays类,大数据运算
实现字符串与基本数据之间转换 将字符串转成基本数据类型方法 例如:将字符串转成成int类型 String str ="123"; int a =Integer.parseInt(s ...
- 14-02 Java Math类,Random类,System类,BigDecimal类
Math类 Math的方法 package cn.itcast_01; /* * Math:用于数学运算的类. * 成员变量: * public static final double PI * pu ...
- Java 基础 常用API (System类,Math类,Arrays, BigInteger,)
基本类型包装类 基本类型包装类概述 在实际程序使用中,程序界面上用户输入的数据都是以字符串类型进行存储的.而程序开发中,我们需要把字符串数据,根据需求转换成指定的基本数据类型,如年龄需要转换成int类 ...
随机推荐
- Pascal's Triangle II 解答
Question Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Ret ...
- OpenRisc-45-or1200的ID模块分析
引言 之前,我们分析了or1200流水线的整体结构,也分析了流水线中IF级,EX级,本小节我们来分析ID(insn decode)级的一些细节. 1,基础 or1200的pipeline的ID阶段包含 ...
- PHP MySQL 创建数据库和表 之 Create
创建数据库 CREATE DATABASE 语句用于在 MySQL 中创建数据库. 语法 CREATE DATABASE database_name 为了让 PHP 执行上面的语句,我们必须使用 my ...
- Spring(三)——AOP
AOP全名为Aspect-Oriented Programming,意思是面向横切面编程,前边我们有过介绍 面向横切面编程AOP的理解 ,我们通过这种编程思想很容易的扩展我们的应用程序. 一,如何 ...
- 在浏览器中输入Google.com并且按下回车之后发生了什么?
作者: skyline75489 来源: skyline75489的博客 发布时间: 2015-03-26 16:57 阅读: 4163 次 推荐: 23 原文链接 [收藏] ...
- iOS安全攻防(二十三):Objective-C代码混淆
iOS安全攻防(二十三):Objective-C代码混淆 class-dump能够非常方便的导出程序头文件,不仅让攻击者了解了程序结构方便逆向,还让着急赶进度时写出的欠完好的程序给同行留下笑柄. 所以 ...
- PHP调用WCF小结
新工作第三周,做了3年多的.Net,突然急转弯做PHP,漂移过弯,速度180迈 由于数据的整合,在项目中不得不使用PHP调用WCF 一头的雾水,网上相关的资料少又少,在phpChina发个帖子,还没有 ...
- resolv.conf 是什么
From Wikipedia, the free encyclopedia This article does not cite any references or sources. Please h ...
- 在windows中使用VMWare安装Mac OS 10.7
请参考http://www.cnblogs.com/huwlnew/archive/2011/11/15/2250342.html http://unmi.cc/vmware9-install-mac ...
- Android 轮询之 Service + AlarmManager+Thread (转)
android中涉及到将服务器中数据变化信息通知用户一般有两种办法,推送和轮询. 消息推送是服务端主动发消息给客户端,因为第一时间知道数据发生变化的是服务器自己,所以推送的优势是实时性高.但服务器主动 ...