C#数字格式
来源:互联网 发布:洗衣店收银软件 编辑:程序博客网 时间:2024/06/05 01:04
using System;
class FormattingNumbers
{
static void Main()
{
decimal theDecNumber = 12345.678m; //the "m" creates a literal of type decimal from a double
//Using the ToString Method
//the number in the format string is the precision specifier
Console.WriteLine("No formatting: " + theDecNumber.ToString());
Console.WriteLine("Currency formatting: " + theDecNumber.ToString("C"));
Console.WriteLine("Exponential formatting: " + theDecNumber.ToString("E"));
Console.WriteLine("Fixed-point formatting: " + theDecNumber.ToString("F2"));
Console.WriteLine("General formatting: " + theDecNumber.ToString("G"));
Console.WriteLine("Number formatting to 2 decimal places: " + theDecNumber.ToString("N2"));
Console.WriteLine("Number formatting to 3 decimal places: " + theDecNumber.ToString("N3"));
Console.WriteLine("Number formatting to 4 decimal places: " + theDecNumber.ToString("N4"));
Console.WriteLine("Percent formatting: " + theDecNumber.ToString("P0"));
int theIntNumber = 123456;
Console.WriteLine("Hexidecimal formatting (for integers): {0} = {1}", theIntNumber, theIntNumber.ToString("X"));
double theDblNumber = 1234567890;
Console.WriteLine("Custom formatting: {0} to US telephone {1}", theDblNumber, theDblNumber.ToString( "(###) ### - ####" ));
//Keep console open if not run through command prompt
Console.Write("/nPress Enter to Continue");
Console.ReadLine();
}
}
N2表示小数点后保留2位....
- C#数字格式
- c# 标准数字格式字符串
- 国际化数字格式输出(C#版)
- C#中的数字格式化 格式日期格式化
- C#标准数字格式字符串输出示例
- C# 自定义数字格式字符串 ToString ###,###,###,##0
- C#中的数字格式化、格式日期格式化
- C# 的数据类型转换 c#字符串转换格式 c#日期数字字符串整形格式转换
- C#将8位日期数字转换成日期格式
- C#将8位日期数字转换成日期格式
- 将人民币大写金额格式转为数字金额格式C#代码
- 【整理】C# ToString格式字符串整理(Format)(数字、日期和枚举的标准格式设置说明符)(SamWang)
- C#验证字符串是否是数字,是否包含中文,是否是邮箱格式,是否是电话格式
- C# 中 ,各种格式的正则表达式(手机号、email、url、时间、身份证、数字、ip)
- DateTime数字类型格式
- 标准数字格式字符串
- java 数字显示格式
- 数字格式类DecimalFormat
- 交换机的配置命令
- 各种交换机端口安全总结(配置实例)
- 和欣
- 用Google挖掘数据
- 《程序员》杂志为程序员准备的鸡汤
- C#数字格式
- Reporting Services(一)
- FreeTextBox改进版
- 详解交换机口令恢复的十个步骤
- 交换机与配线架端口对应快速查找法
- Java Annotation入门
- [原创]数学是什么
- Java开发者的十大戒律(转)
- 感叹"浪潮之颠"