如果您想要四舍五入小数点,请查看 Math.Round ()
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
我只能获得两个小数点位数,但使用这个代码我才能获得1156.547。 要显示两个小数位,我必须使用哪种格式?
如果您想要四舍五入小数点,请查看 Math.Round ()
您的问题是要显示小数点后两个位数。 使用以下字符串. format 将会帮助 :
String.Format("{0:.##}", Debitvalue)
将显示数字,以小数点后两个位数为准(例如2.10将显示为2.1)。
如果您想要总是显示两个小数位数( 如 2. 10 将显示为 2. 10), 请使用“ { 0:. 00} ” 。
或者,如果您想要显示货币符号,请使用以下符号:
String.Format("{0:C}", Debitvalue)
使用 < a href=> "http://msdn.microsoft.com/en-us/library/as4h66hd\\\\ code>Math.Round () 来四舍五入到小数点后两位位
decimal DEBITAMT = Math.Round(1156.547m, 2);
如果您想要 ALWAYS 显示两个小数点位数(即使您的数字只有一个小数点位数),最好的方法是使用
yournumber.ToString("0.00");
<强 > I 使用 强>
decimal Debitvalue = 1156.547m;
decimal DEBITAMT = Convert.ToDecimal(string.Format("{0:F2}", Debitvalue));
这是另一种方法
decimal decimalRounded = Decimal.Parse(Debitvalue.ToString("0.00"));
仅用于显示, string
的属性可用作以下的属性 。
double value = 123.456789;
String.Format("{0:0.00}", value);
使用 System.Math.Round
。 此值可以指定给其他人或按要求操作 。
double value = 123.456789;
System.Math.Round(value, 2);
另一条路:
decimal.Round(decimalvalue, 2, MidpointRounding.AwayFromZero);
可能是其他例子的变体, 但我使用这个方法也确保小数位之前显示点, 而不是逗号 :
someValue.ToString("0.00", CultureInfo.InvariantCulture)
另一个选项是使用 Decimal. Round 方法
如果有人在寻找显示小数位的方法, 即使以 < 强 > " 00" 强 > 结尾, 请使用这个 :
String.Format("{0:n1}", value)
<强>参考: 强>
要显示两位十进制位数,请尝试给定的语法 。
字符串 Format (“ {0: 0.00} ”, 除位值)
double doubleNumber= 1.1; // 7.25 // 700.0
string uptwoDecimalPlaces= number.ToString("F2");
在有些测试中,它以这种方式运作得非常完美:
Decimal.Round(value, 2);
希望这有帮助
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber. I want to create a many to many association ...
How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...
Since I cannot order my dictionary, what is the best way of going about taking key value pairs and also maintaing an index?
Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...