本文来自:http://www.cnblogs.com/del/archive/2011/01/03/1924746.html
 
成员:

/* 字段 */
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);
}

 
 
分类: C# 与 Net

学用 ASP.Net 之 System.Math 类的更多相关文章

  1. 学用 ASP.Net 之 System.Collections.ArrayList 类

    ArrayList 是 .Net 的动态数组. 主要成员: /* 静态方法 */ ArrayList.Adapter() //把其他 IList 对象包装为 ArrayList 使用 ArrayLis ...

  2. 08 正则表达式,Math类,Random,System类,BigInteger,BigDecimal,Date,DateFormat,Calendar

    正则表达式:    是指一个用来描述或者匹配一系列符合某个语法规则的字符串的单个字符串.其实就是一种规则.有自己特殊的应用. public class Demo2_Regex { public sta ...

  3. 基本类型包装类、System类、Math类、Arrays类、大数据运算

    1 基本类型包装类 Java中想对8种基本数据类型进行复杂操作很困难. 实际程序界面上用户输入的数据都是以字符串类型进行存储的. 程序开发中,需要把字符串转换成指定的基本数据类型. 1.1基本数据类型 ...

  4. 正则表达式、Calendar类、SimpleDateFormat类、Date类、BigDecimal类、BigInteger类、System类、Random类、Math类(Java基础知识十四)

    1.正则表达式的概述和简单使用 * A:正则表达式(一个字符串,是规则)     * 是指一个用来描述或者匹配一系列符合某个语法规则的字符串的单个字符串.其实就是一种规则.有自己特殊的应用. * B: ...

  5. JAVA学习第四十五课 — 其它对象API(一)System、Runtime、Math类

    一.System类 1. static long currentTimeMillis() 返回以毫秒为单位的当前时间. 实际上:当前时间与协调世界时 1970 年 1 月 1 日午夜之间的时间差(以毫 ...

  6. Java常用类之【Math类、Random类、System类、Runtime类】

    一.Math类 Math类 [绝对值]Math.abs();//返回对应类型的绝对值 [最大值和最小值]Math.max(int a, int b) ,Math.min(int a,int b);(其 ...

  7. java 基本类型包装类,system类,Math类,Assrays类,大数据运算

    实现字符串与基本数据之间转换 将字符串转成基本数据类型方法 例如:将字符串转成成int类型 String str ="123"; int a =Integer.parseInt(s ...

  8. 14-02 Java Math类,Random类,System类,BigDecimal类

    Math类 Math的方法 package cn.itcast_01; /* * Math:用于数学运算的类. * 成员变量: * public static final double PI * pu ...

  9. Java 基础 常用API (System类,Math类,Arrays, BigInteger,)

    基本类型包装类 基本类型包装类概述 在实际程序使用中,程序界面上用户输入的数据都是以字符串类型进行存储的.而程序开发中,我们需要把字符串数据,根据需求转换成指定的基本数据类型,如年龄需要转换成int类 ...

随机推荐

  1. 剑指offer-面试题3.二维数组中的查找

    题目:在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增 的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断该数组中是否有该整数. 算法流程如下: 比如一个 ...

  2. 51操作各种demo 驱动

    24C02 bit write=0; //写24C02的标志: sbit sda=P2^0; sbit scl=P2^1; void delay0() { ;; } void start() //开始 ...

  3. 使用ObjectInputStream的readObject()方法如何判断读取到多个对象的结尾

    摘自http://blog.csdn.net/fjdingsd/article/details/46765803 使用ObjectInputStream的readObject()方法如何判断读取到多个 ...

  4. C语言结构体的内存对齐问题

    在C语言开发当中会遇到这样的情况: #include <stdio.h> struct test { int a; char b; }; int main(int argc, const ...

  5. 通过项目逐步深入了解Mybatis<三>

    Mybatis 高级知识 安排:对订单商品数据模型进行分析 订单商品数据模型 数据模型分析思路: 1.每张表记录的数据内容(分模块对每张表记录的内容进行熟悉,相当于学习系统需求的过程) 2.每张表重要 ...

  6. fullcalender

    http://blog.csdn.net/francislaw/article/details/7740630 引用 <link rel="stylesheet" href= ...

  7. 用maven骨架生成项目速度慢的问题

    最近从IntelliJ Idea 14的Community版本切换到Ultimate. 问题出现 最近从IntelliJ Idea 14的Community版本切换到Ultimate,key是从网络上 ...

  8. CSS3实现图片鼠标悬浮放大效果

    .excerpt .focus a img{ -webkit-transition: all ease .3s; transition: all ease .3s }.excerpt .focus a ...

  9. 为net-snmp添加读readTimeTicks

    function readTimeTicks(time){ if(time === 0) return ''; var d = 0, h = 0, m = 0, s = 0; d = parseInt ...

  10. BeeswaxException 以及其他问题

    Could not read table BeeswaxException(handle=QueryHandle(log_context='ae18ae74-518f-400b-b4b0-d399ed ...