DataFormatString在C#中的数字格式化技能
在C#中,可使用DataFormatString来实现数字格式化。下面罗列了一些常见的数字格式化技能:
decimal amount = 123.45m;
string formattedAmount = string.Format("{0:C}", amount);
// 输出 $123.45
double percentage = 0.75;
string formattedPercentage = string.Format("{0:P}", percentage);
// 输出 75.00%
double number = 1234.56789;
string formattedNumber = string.Format("{0:N2}", number);
// 输出 1,234.57
double scientificNumber = 123456789;
string formattedScientificNumber = string.Format("{0:E}", scientificNumber);
// 输出 1.234568E+008
double customNumber = 12.3456;
string formattedCustomNumber = string.Format("{0:0.00}", customNumber);
// 输出 12.35
这些是一些常见的数字格式化技能,在实际利用中可以根据需求进行自定义设置。
tiktok粉丝购买:https://www.smmfensi.com/
TOP