学用 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类 ...
随机推荐
- LeeCode-Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. For ...
- UML_活动图
一.活动图的组成元素 Activity Diagram Element 1.活动状态图(Activity) 2.动作状态(Actions) 3.动作状态约束(Action Constraints) 4 ...
- HBase 4、Phoenix安装和Squirrel安装
描述 现有hbase的查询工具有很多如:Hive,Tez,Impala,Shark/Spark,Phoenix等.今天主要记录Phoenix. phoenix,中文译为“凤凰”,很美的名字.Phoen ...
- FlashBack-SCN-TIMESTAMP
一.基于时间(as of timestamp)的flashback1.创建表create table flash_tab(id,vl) as select rownum,oname from ( se ...
- Html5 代码
随着HTML5的流行,许多网站开始介绍HTML5元素和属性的用法,以及各种教程,并且越来越多老的浏览器开始兼容HTML5. 本文作者编译了10段非常实用的HTML5代码片段,开发者可以直接拿过去使 ...
- [记录]关于vertical-align单/多选框与说明文字对齐效果
效果图: 第一张使用label标签,第二张没有使用.. 使用label标签,middle对齐方式的单选框下降了1px 而没有使用label标签,sub对齐方式的 却 居 中 了 =_= 不太理解 ...
- phantomjs API
phantomjs使用说明 phantomjs实现了一个无界面的webkit浏览器.虽然没有界面,但dom渲染.js运行.网络访问.canvas/svg绘制等功能都很完备,在页面抓取. ...
- sublime 前端开发工具
http://code.kpman.cc/2014/10/14/sublime-text-3-mac-%E6%8C%87%E5%8D%97/ gif 屏幕录制:http://recordit.co/ ...
- SQL in Qt (一)
Connecting to Databases To access a database with QSqlQuery or QSqlQueryModel, create and open one o ...
- java教程
http://www.xfonlineclass.com/ http://java.itcast.cn/ http://www.xasxt.com/index.php/list/161 [UI]htt ...