【数据库 数据类型float到C#类型decimal, float数据类型转化无效】教程文章相关的互联网学习教程文章

c#中decimal ,double,float的区别

转自:http://www.cnblogs.com/lovewife/articles/2466543.html单精度就是指4个字节的浮点数,即float双精度就是指8个字节的浮点数,即doubledecimal是高精度 浮点型 Name CTS Type Description Significant Figures Range (approximate) float System.Single 32-bit single-precision floating point 7 ±1.5 × 10?45 to ±3.4 × 1038 double System.Double 64-bit double-precision floating point 15/16 ±5.0 × 10 ?324 to ±1.7 ×...

WinCE的C#编程,对float型进行四舍五入保留两位小数,小数进行四舍五入操作,Math.Round的应用案例。

private float ConvertFloat4Se5Ru(float flotValue) { int iValue = (int)Math.Round(flotValue * 10000); //小数点后两位前移,并四舍五入 flotValue = (float)(iValue / 10000.00f); return flotValue; }申明:以上文字为“武汉汉码科技有限公司”原创,转载时务必注明出处。技术分享。沟通你我。共同进步!www.hanma-scan.com原文:http://www.cnblogs.com/zsychanpi...

C#中将string转换为float【代码】

string s = "123.2";//方法1float f1 = Convert.ToSingle(s);//方法2float f2;if (!float.TryParse(s, out f2)){Console.WriteLine("无法转换!");} float volume = 0.5F; //double 转float 原文:http://www.cnblogs.com/tanrong/p/7074253.html

C#中对于float,double,decimal的误解(转载)【代码】

浮点型 NameCTS TypeDescriptionSignificant FiguresRange (approximate)float System.Single 32-bit single-precision floating point7±1.5 × 10?45 to ±3.4 × 1038double System.Double 64-bit double-precision floating point15/16±5.0 × 10 ?324 to ±1.7 × 10308如果我们在代码中写一个12.3,编译器会自动认为这个数是个double型。所以如果我们想指定12.3为float类型,那么你必须在数字后面加上F/f:float f = 12.3F; decimal...

数据库 数据类型float到C#类型decimal, float数据类型转化无效

今天运行系统突然出错,数据类型转化无效,错误在system.data.sqlclient.get_decimal()方法,初步估计是数据库的float类型转换为c#的decimal类型时出错了,实体类使用的是decimal?类型,心想就算数据库里的数值是空,也不能出现转换错误啊。 网上百般搜索,很多人遇到类似情况,多数是直接去float类型时候出错,如(float)dr[0],后来看到有说应该是先转化成double,然后在转化成float就可以了 尝试了一下把实体类的decimal?类型的字...

在C#项目中需要用double类型操作MSSQL float类型数据(附C#数据类型和SQL数据类型对照)

<summary>/// 数据库中与C#中的数据类型对照/// </summary>/// <param name="type"></param>/// <returns></returns>private string ChangeToCSharpType(string type){string reval = string.Empty;switch (type.ToLower()){case "int":reval = "Int32";break;case "text":reval = "String";break;case "bigint":reval = "Int64";break;case "binary":reval = "System.Byte[]";break;case "bit":reval = "Boolean";break;case "cha...

c#-将对象强制转换为float类型,但看起来像struct System.Single【代码】

我的代码如下所示,并且float是Control.CornerRadius的数据类型:Application.Current.Resources.TryGetValue("RoundButtonSize", out object size); control.CornerRadius = ((float)size) / 2;但是,当我在第二行进行强制转换时,它表示无效的强制转换,当我在此处进行检查时,我发现它没有强制转换为浮点数:var a = (float)size ;它说a的数据类型是Struct System.Single 有人可以告诉我演员阵容我做错了什么吗?解决方法:CornerRadi...

C#-在结构体中使用float []【代码】

我的结构中是否可以有一个浮点常量private struct MyStruct {public const float[] TEST = new float[] {1,2}; }上面是我的第一个猜测,但是不起作用. 有任何想法吗?解决方法:不,你不能有一个const float [] 最常用的是public static readonly float[] TEST = new float[] {1,2}; 但是该数组本身并不是一成不变的,因此您经常遵循public static readonly IList<float> TEST = new ReadOnlyCollectioN(new float[] {1,2}); 最后,最后...

c# – 从C本机插件更新float数组【代码】

在尝试将数组从C传递到C#时,我看到了一个非常奇怪的问题.我正在使用Marshal.Copy(具体来说:https://msdn.microsoft.com/en-us/library/a53bd6cz(v=vs.110).aspx). 问题:从C到C#的浮点数组在结果数组中产生一些NaN.(注意:我在Unity游戏引擎的上下文中工作) 码 示例C代码:extern "C" bool UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API getSomeFloats(float** points, int* count) {std::vector<float> results;std::vector<SOME_...

C# int uint long ulong byte sbyte float double decimal 范围,及类型!【代码】

static void Main(string[] args){Console.WriteLine(" byte {0,7:g}{1,32:g}{2,32:g}",typeof(byte).Name, byte.MinValue, byte.MaxValue);Console.WriteLine(" sbyte {0,7:g}{1,32:g}{2,32:g}",typeof(sbyte).Name, sbyte.MinValue, sbyte.MaxValue);Console.WriteLine(" short {0,7:g}{1,32:g}{2,32:g}", typeof(short).Name, short.MinValue, short.MaxValue);Console.WriteLine(" ushort {0,7:g}{1,32:g}{2,32:g}", t...

在c#中将string []转换为Decimal [],int [],float [] .double []【代码】

string[] txt1 = new string[]{"12","13"};this.SetValue(txt1, v => Convert.ChangeType(v, typeof(decimal[]), null));它抛出一个错误 – 对象必须实现IConvertible. 我还想要一个代码来转换string [] To Decimal [],int [],float [] .double []解决方法:您无法将字符串[]直接转换为十进制[],所有元素都必须单独转换为新类型.相反,你可以使用Array.ConvertAllstring[] txt1 = new string[]{"12","13"}; decimal[] dec1 = Array.C...

c# – 将float.MaxValue转换为Long抛出异常?【代码】

试图获取float.MaxValue的整数部分,但它抛出错误?long l = Convert.ToInt64(float.MaxValue);Console.WriteLine(l);错误:算术运算导致溢出.解决方法:float的最大值为3.4E 38,而long的最大值为9.2E 18.因此,float.MaxValue不适合长. 指定大于Int64.MaxValue或小于Int64.MinValue的值时,Convert.ToInt64方法抛出OverflowException. 如果您只想获取float.MaxValue的整数值,请参阅this question的相关答案.但请注意,即使剥离了浮点,浮...

c# – 为什么相同的值与float和double 不同【代码】

参见英文答案 > Difference between decimal, float and double in .NET? 16个考虑这个计划float a = 0.7f;if (a < 0.7) {Console.WriteLine("Less"); }输出为Less.为什么??解决方法:因为0.7没有精确表示为float或double:它不是2的负幂的精确和. 碰巧最接近的0.7表示为浮点数约为0.69999998807907104492,而最接近的双重表示为0.69999999999999995559.如您所见,double略高,这解释了程序的行为...

【转载】 C#中float、double以及decimal类型有何不同

在C#语言中,float、double以及decimal类型都可以用来表示小数,但三者还是有一定的不同,有效数字为相比的话,decimal类型的有效数字最大,float类型最小。计算浮点类型的运算,如果只有float和double类型选择的话,建议选择double类型,计算误差相对小一些。如果是涉及到财务或者货币金额等金融计算,建议使用十进制decimal类型,decimal的有效位数很大,达到了28位,可以保证计算结果更为精准。 针对这3种类型,其中float和doub...

【转载】C#中float.TryParse方法和float.Parse方法的异同之处

在C#编程过程中,float.TryParse方法和float.Parse方法都可以将字符串string转换为单精度浮点类型float,但两者还是有区别,最重要的区别在于float.TryParse方法在字符串无法转换为float类型的情况下不会引发程序异常,而float.Parse方法则是直接抛出程序异常。float.TryParse方法在无法转换的情况下返回false,并且使用了out参数进行转换。 float.TryParse方法的签名为:static bool TryParse(string s, out Single result) float...

DECIMAL - 相关标签