C#字符串格式化

数值规范

也可写成int money = 368; money .ToString("C");

string.Format("金额:{0:C}", 368); => ¥368.00

string.Format("科学计数法:{0:C}", 12000.1); => 1.200001E+005

string.Format("分割数字:,{0:E0}", 123456789); => 123,456,789

string.Format("π取两位小数:{0:F2}", Math.PI); => 3.14

string.Format("16进制:{0:X4}", 33); => 0021

string.Format("百分比:{0:P0}", 0.99); => 99%

日期格式化

DateTime strDate = DateTime.Now;

也可写成strDate.ToString("Y");

string.Format("短日期格式:{0:d}", strDate); =>短日期格式:2024/4/29

string.Format("长日期格式:{0:D}", strDate); =>长日期格式:2024年4月29日

string.Format("完整日期格式:{0:f}", strDate); =>完整日期格式:2024年4月29日 16:26

string.Format("短时间格式:{0:t}", strDate); =>短时间格式:16:26

string.Format("长时间格式:{0:T}", strDate); =>长时间格式:16:26:54

string.Format("月日格式:{0:M}", strDate); =>月日格式:4月29日

string.Format("年月格式:{0:y}", strDate); =>年月格式:2024年4月

相关推荐
霸王•吕布1 小时前
C#-使用OpenTK渲染3D模型
c#·opentk·glcontrol
游乐码2 小时前
c#封装成员变量和成员方法和访问修饰符
开发语言·c#
Never_Satisfied2 小时前
在c#中,Jint的AsString()和ToString()的区别
服务器·开发语言·c#
Never_Satisfied2 小时前
在c#中,获取文件的大小
java·开发语言·c#
weixin_468466852 小时前
PyTorch导出ONNX格式分割模型及在C#中调用预测
人工智能·pytorch·深度学习·c#·跨平台·onnx·语义分割
光泽雨11 小时前
C# 中 Assembly 类详解
开发语言·c#
少控科技11 小时前
C#基础训练营 - 02 - 运算器
开发语言·c#
两千次16 小时前
图像的处理 图片裁剪工具方法 图片按比例缩放的工具方法
c#
Sunsets_Red17 小时前
浅谈随机化与模拟退火
java·c语言·c++·python·算法·c#·信息学竞赛
两千次19 小时前
图像的处理 图像转haclon
c#