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月

相关推荐
(initial)9 小时前
B-02. Shared Memory 深度优化:从 Bank Conflict 到 Tensor Core Swizzling
开发语言·c#
fdc201716 小时前
解耦的艺术:用责任链模式构建可插拔的文件处理流水线
c#·.net·责任链模式
bugcome_com16 小时前
【C# 数组详解】Array 定义、初始化、遍历、内存原理与面试高频问题
后端·c#·asp.net
小码编匠16 小时前
WPF 如何在 MVVM模式下实现 DataGrid编辑功能
后端·c#·.net
游乐码17 小时前
c#扩展方法
开发语言·c#
qq_4542450318 小时前
基于ECS的工作流编排框架
数据结构·c#
qq_454245031 天前
BuildTemplateGraph 函数深度解析:动态节点图构建的架构设计与核心价值
数据结构·c#
qq_454245031 天前
SkeletonFlow:基于组合子逻辑与范畴论的数据流处理框架
数据结构·c#
游乐码1 天前
c#静态类和静态构造函数
开发语言·c#
net3m331 天前
自动分工 现象时,一共有几种可能得权重组合变化,如何确保这些组合的扫描时的不发生组合爆炸
人工智能·c#·ai编程