陋室铭
永远也不要停下学习的脚步(大道至简至易)

posts - 2167,comments - 570,views - 413万
"%"为取余号,不用多说。   
"/"号现在整形运算是取整,浮点运算时为除法运算,如54/10结果为5,54.0/10.0结果为5.4而且取整时不进行四舍五入只取整数部分,如54/10和56/10是5.   
Math.Celling()取整数的较大数,相当于不管余数是什么都会进一位。如Math.Celling(54.0/10.0)结果为6.   
Math.Floor()取整数的较小数,相当于"/"号,即不管余数部分是什么都不进行进位。如Math.Floor(56.0/10.0)的结果是5.
代码如下: using System;
using System.Collections.Generic;
 using System.Text;
namespace ConsoleApplication5
 { class Program { static void Main(string[] args)
 { Console.WriteLine("(54/10):{0}", 54 / 10);
Console.WriteLine("(56/10):{0}", 56/ 10);
Console.WriteLine("(54.0%10.0):{0}", 54.0 % 10.0);
Console.WriteLine("(56.0%10.0):{0}", 56.0 % 10.0);
Console.WriteLine("Math.Celling(54.0/10.0):{0}", Math.Ceiling(54.0 / 10.0));
Console.WriteLine("Math.Celling(56.0/10.0):{0}", Math.Ceiling(56.0 / 10.0));
 Console.WriteLine("Math.Floor(54.0/10.0):{0}", Math.Floor(54.0 / 10.0));
 Console.WriteLine("Math.Floor(56.0/10.0):{0}", Math.Floor(56.0 / 10.0)); } } }
C#中,关于除法"/"运算得一点问题。
  现在C#与法中,"/"除后所得的值的类型,跟他的除数和被除数的类型有关。如: int a=4; int b=5; float c=a/b ;   则结果为0(因为会先进行int的除法操作,得出结果0,再将结果转为float 0;);   总之,得出的数都是整形的,最终发觉原来除后所得的值的类型,跟他的除数和被除数的类型有关。所以,应写成: float a=3; float b=5; float c=a/b; 这样,才能得出正确的结论!
posted on   宏宇  阅读(150188)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
历史上的今天:
2012-08-22 3D打印机(3D Printers)
2010-08-22 好好整理了一下胡子
2008-08-22 ServerVariable(环境变量)
2008-08-22 Net线程问题解答(转)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示