栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

c# 取余数 浮点数

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

c# 取余数 浮点数

【实例简介】

【实例截图】

【核心代码】

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace Calculator

{

public partial class Form1 : Form

{

string str, opp, opp1;

double num1, num2, result;

public Form1()

{

InitializeComponent();

}

private void number(object sender, EventArgs e)

{

Button b = (Button)(sender);

str = b.Text;

if (txtOutput.Text == "0")

{

txtOutput.Text = str;

}

else

txtOutput.Text = txtOutput.Text str;

}

private void operator1(object sender, EventArgs e)

{

Button b = (Button)(sender);

if (b.Text == " ")

{

num1 = double.Parse(txtOutput.Text);

txtOutput.Text = "";

opp = " ";

opp1 = "";

}

else if (b.Text == "-")

{

num1 = double.Parse(txtOutput.Text);

txtOutput.Text = "";

opp = "-";

opp1 = "";

}

else if (b.Text == "*")

{

num1 = double.Parse(txtOutput.Text);

txtOutput.Text = "";

opp = "*";

opp1 = "";

}

else if (b.Text == "/")

{

num1 = double.Parse(txtOutput.Text);

txtOutput.Text = "";

opp = "/";

opp1 = "";

}

else if (b.Text == "=")

{

if (opp1 != "=")

{

num2 = double.Parse(txtOutput.Text);

}

if (opp == " ")

{

num1 = num1 num2;

txtOutput.Text = "" num1.ToString();

}

else if (opp == "-")

{

num1 = num1 - num2;

txtOutput.Text = "" num1.ToString();

}

else if (opp == "*")

{

num1 = num1 * num2;

txtOutput.Text = "" num1.ToString();

}

else if (opp == "/")

{

if (num2 == 0)

{

txtOutput.Text = "除数不能为零";

}

else

{

num1 = num1 / num2;

txtOutput.Text = "" num1.ToString();

}

}

opp1 = "=";

}

}

private void operator2(object sender, EventArgs e)

{

Button b = (Button)(sender);

if (b.Text == ".")

{

str = txtOutput.Text;

int index = str.IndexOf(".");

if (index == -1)

{

txtOutput.Text = str ".";

}

}

else if (b.Text == "退格

{

if (txtOutput.Text != "")

{

str = txtOutput.Text;

str = str.Substring(0, str.Length - 1);

txtOutput.Text = str;

}

}

else if (b.Text == "CE")

{

txtOutput.Text = "0";

}

else if (b.Text == "C")

{

result = num1 = num2 = 0;

str = null;

opp = null;

txtOutput.Text = "0";

}

else if (b.Text == "sqrt")

{

num1 = double.Parse(txtOutput.Text);

result = Math.Sqrt(num1);

txtOutput.Text = result.ToString();

}

else if (b.Text == "1/x")

{

num1 = double.Parse(txtOutput.Text);

result = 1 / num1;

txtOutput.Text = result.ToString();

}

else if (b.Text == "%")

{

num1 = double.Parse(txtOutput.Text);

result = num1 / 100;

txtOutput.Text = result.ToString();

}

opp1 = "";

}

}

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1023505.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号