## 学用 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);
}``````

### 涂孟超

niunan
2017/01/01
0
0
ASP.net与JavaEE语法、内置对象的对比

1 各自的HelloWord版本 1.1 ASP <% Response.Write("hello asp") %> 文件名为test.asp。 1.2 ASP.net <%@ page Language="C#" %> <% Response.Write("hello asp.net"); %> 文件名为test.aspx......

2017/12/24
0
0
.NET Core开发日志——从ASP.NET Core Module到KestrelServer

ASP.NET Core程序现在变得如同控制台(Console)程序一般，同样通过Main方法启动整个应用。而Main方法要做的事情很简单，创建一个WebHostBuilder类，调用其Build方法生成一个WebHost类，最后启...

Ken.W
07/14
0
0
Asp.Net Core 2.0 项目实战（7）MD5加密、AES&DES对称加解密

Asp.Net Core 2.0 项目实战（1） NCMVC开源下载了 Asp.Net Core 2.0 项目实战（2）NCMVC一个基于Net Core2.0搭建的角色权限管理开发框架 Asp.Net Core 2.0 项目实战（3）NCMVC角色权限管理前...

04/26
0
0
Asp.Net MVC3 简单入门第一季（五） 通过Asp.Net MVC的区域功能实现将多个MVC项目部署到一个站点

aicoder
2011/10/12
0
0

KaliLinux常用服务配置教程DHCP服务工作流程

KaliLinux常用服务配置教程DHCP服务工作流程 DHCP服务工作流程如图1.1所示。 具体的工作流程如下所示： （1）DHCP客户端以广播的方式发出DHCP Discover报文。 （2）所有的DHCP服务器（DHCP ...

1分钟前
0
0
Spring Junit单元测试配置

<dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>5.1.2.RELEASE</version></dependency><dependency> <group......

TonyTaotao
6分钟前
0
0

Java搬砖工程师
8分钟前
0
0

8分钟前
0
0