Axx
,其中 A
是格式说明符,xx
是精度说明符。下面是一些常用的标准数字格式字符串:C
或 c
)double number = 1234.56; string currency = number.ToString("C"); Console.WriteLine(currency); // 输出结果根据系统区域设置可能为 $1,234.56 等
D
或 d
)
int num = 123; string decimalStr = num.ToString("D5"); Console.WriteLine(decimalStr); // 输出: 00123
E
或 e
)
E
表示使用大写字母 E
,e
表示使用小写字母 e
double num2 = 1234.56; string scientific = num2.ToString("E3"); Console.WriteLine(scientific); // 输出: 1.235E+003
F
或 f
)
double num3 = 123.456; string fixedPoint = num3.ToString("F2"); Console.WriteLine(fixedPoint); // 输出: 123.46
G
或 g
)
double num4 = 1234.56; string general = num4.ToString("G"); Console.WriteLine(general); // 输出: 1234.56
P
或 p
)
double num5 = 0.1234; string percentage = num5.ToString("P2"); Console.WriteLine(percentage); // 输出: 12.34%
X
或 x
)
X
表示使用大写字母,x
表示使用小写字母。int num6 = 255; string hex = num6.ToString("X"); Console.WriteLine(hex); // 输出: FF
0
:占位符
double num7 = 12.3; string custom1 = num7.ToString("000.00"); Console.WriteLine(custom1); // 输出: 012.30
#
:数字占位符
double num8 = 12.3; string custom2 = num8.ToString("###.##"); Console.WriteLine(custom2); // 输出: 12.3
.
:小数点
double num9 = 1234; string custom3 = num9.ToString("#.00"); Console.WriteLine(custom3); // 输出: 1234.00
,
:千位分隔符
int num10 = 1234567; string custom4 = num10.ToString("#,##0"); Console.WriteLine(custom4); // 输出: 1,234,567
%
:百分比符号
double num11 = 0.123; string custom5 = num11.ToString("#%"); Console.WriteLine(custom5); // 输出: 12%
这个也算最简单的了。只为只考虑三位数。
-- 钟铧若岩这个oracle的内部机制,不清楚啊。
-- 钟铧若岩
Copyright © 2025 钟铧若岩
Powered by .NET 9.0 on Kubernetes
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?