Standard Numeric Format Strings
The following table describes the standard numeric format specifiers and displays sample output produced by each format specifier. See the Notes section for additional information about using standard numeric format strings, and the Example section for a comprehensive illustration of their use.
|
Format specifier |
Name |
Description |
Examples |
|---|---|---|---|
|
"C" or "c" |
Currency |
Result: A currency value. Supported by: All numeric types. Precision specifier: Number of decimal digits. Default precision specifier: Defined byNumberFormatInfo.CurrencyDecimalDigits. More information: The Currency ("C") Format Specifier. |
123.456 ("C", en-US) -> $123.46 123.456 ("C", fr-FR) -> 123,46 € 123.456 ("C", ja-JP) -> ¥123 -123.456 ("C3", en-US) -> ($123.456) -123.456 ("C3", fr-FR) -> -123,456 € -123.456 ("C3", ja-JP) -> -¥123.456 |
|
"D" or "d" |
Decimal |
Result: Integer digits with optional negative sign. Supported by: Integral types only. Precision specifier: Minimum number of digits. Default precision specifier: Minimum number of digits required. More information: The Decimal("D") Format Specifier. |
1234 ("D") -> 1234 -1234 ("D6") -> -001234 |
|
"E" or "e" |
Exponential (scientific) |
Result: Exponential notation. Supported by: All numeric types. Precision specifier: Number of decimal digits. Default precision specifier: 6. More information: The Exponential ("E") Format Specifier. |
1052.0329112756 ("E", en-US) -> 1.052033E+003 1052.0329112756 ("e", fr-FR) -> 1,052033e+003 -1052.0329112756 ("e2", en-US) -> -1.05e+003 -1052.0329112756 ("E2", fr_FR) -> -1,05E+003 |
|
"F" or "f" |
Fixed-point |
Result: Integral and decimal digits with optional negative sign. Supported by: All numeric types. Precision specifier: Number of decimal digits. Default precision specifier: Defined byNumberFormatInfo.NumberDecimalDigits. More information: The Fixed-Point ("F") Format Specifier. |
1234.567 ("F", en-US) -> 1234.57 1234.567 ("F", de-DE) -> 1234,57 1234 ("F1", en-US) -> 1234.0 1234 ("F1", de-DE) -> 1234,0 -1234.56 ("F4", en-US) -> -1234.5600 -1234.56 ("F4", de-DE) -> -1234,5600 |
|
"G" or "g" |
General |
Result: The most compact of either fixed-point or scientific notation. Supported by: All numeric types. Precision specifier: Number of significant digits. Default precision specifier: Depends on numeric type. More information: The General ("G") Format Specifier. |
-123.456 ("G", en-US) -> -123.456 123.456 ("G", sv-SE) -> -123,456 123.4546 ("G4", en-US) -> 123.5 123.4546 ("G4", sv-SE) -> 123,5 -1.234567890e-25 ("G", en-US) -> -1.23456789E-25 -1.234567890e-25 ("G", sv-SE) -> -1,23456789E-25 |
|
"N" or "n" |
Number |
Result: Integral and decimal digits, group separators, and a decimal separator with optional negative sign. Supported by: All numeric types. Precision specifier: Desired number of decimal places. Default precision specifier: Defined byNumberFormatInfo.NumberDecimalDigits. More information: The Numeric ("N") Format Specifier. |
1234.567 ("N", en-US) -> 1,234.57 1234.567 ("N", ru-RU) -> 1 234,57 1234 ("N1", en-US) -> 1,234.0 1234 ("N1", ru-RU) -> 1 234,0 -1234.56 ("N3", en-US) -> -1,234.560 -1234.56 ("N3", ru-RU) -> -1 234,560 |
|
"P" or "p" |
Percent |
Result: Number multiplied by 100 and displayed with a percent symbol. Supported by: All numeric types. Precision specifier: Desired number of decimal places. Default precision specifier: Defined by NumberFormatInfo.PercentDecimalDigits. More information: The Percent ("P") Format Specifier. |
1 ("P", en-US) -> 100.00 % 1 ("P", fr-FR) -> 100,00 % -0.39678 ("P1", en-US) -> -39.7 % -0.39678 ("P1", fr-FR) -> -39,7 % |
|
"R" or "r" |
Round-trip |
Result: A string that can round-trip to an identical number. Supported by: Single, Double, and BigInteger. Precision specifier: Ignored. More information: The Round-trip ("R") Format Specifier. |
123456789.12345678 ("R") -> 123456789.12345678 -1234567890.12345678 ("R") -> -1234567890.1234567 |
|
"X" or "x" |
Hexadecimal |
Result: A hexadecimal string. Supported by: Integral types only. Precision specifier: Number of digits in the result string. More information: The HexaDecimal ("X") Format Specifier. |
255 ("X") -> FF -1 ("x") -> ff 255 ("x4") -> 00ff -1 ("X4") -> 00FF |
|
Any other single character |
Unknown specifier |
Result: Throws a FormatException at run time. |
Standard Numeric Format Strings的更多相关文章
- 字符串格式化格式 -- Numeric Format Strings
- [Python] Format Strings in Python
Single quotes and double quotes can both be used to declare strings in Python. You can even use trip ...
- C# 字符串格式
1.数字补零输出字符串 String.Format("{0:D6}",123); 2.字符串靠左输出6位 String.Format("{0,-6}",&quo ...
- decimal.tostring()格式
nt/Decimal.ToString 方法 (String, IFormatProvider) decimal value = 16325.62m; string specifier; Cult ...
- Dynamics CRM教程:图表的Top设置及导出修改和导入
关注本人微信和易信公众号: 微软动态CRM专家罗勇,回复144或者20150412可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me! 上一篇博客制作的图表放在Dashb ...
- JVM Specification 9th Edition (4) Chapter 4. The class File Format
Chapter 4. The class File Format Table of Contents 4.1. The ClassFile Structure 4.2. Names 4.2.1. Bi ...
- clang format 官方文档自定义参数介绍(中英文)
官方文档:http://clang.llvm.org/docs/ClangFormatStyleOptions.html 中文 在代码中配置样式 当使用 clang::format::reformat ...
- Java基础扫盲系列(-)—— String中的format
Java基础扫盲系列(-)-- String中的format 以前大学学习C语言时,有函数printf,能够按照格式打印输出的内容.但是工作后使用Java,也没有遇到过格式打印的需求,今天遇到项目代码 ...
- strings.h 与 string.h 头文件的区别
今天使用 man string 来查看 string 文件的使用的方法(毕竟里面的函数名字和传入参数和发挥参数的类型,如果一段时间不使用,会产生遗忘.) 偶然发现,string.h 的man page ...
随机推荐
- android 20 Intnet类重要的成员变量
Intnet类重要的成员变量: <intent-filter> <action android:name="android.intent.action.MAIN" ...
- cygwin下用mysql c api连接数据库详解
一.典型错误: 错误1: 命令: gcc -I /usr/include/mysql/ -L /lib/ -lmysqlclient main.c 错误: /tmp/ccT0KqUQ.o:main.c ...
- java文件处理工具类
import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.BufferedRead ...
- android学习笔记----JNI中的c控制java
面向对象的底层实现 java作为面向对象高级语言,可对现实世界进行建模.和面向过程不同的是面向对象软件的编写不是流程的堆积,而是对业务逻辑的多视角分解和分类.其过程大致为: 1).将知识分解 ...
- 兼容IE浏览器的placeholder【超不错】
jQuery EnPlaceholder plug (兼容IE浏览器的placeholder)使用 >>>>>>>>>>>>&g ...
- eclipse(myEclipse) 配置maven项目
工作中在myeclipse中导入maven工程后,在pom.xml文件目录执行了mvn eclipse:eclipse 后,发现项目中缺少"Maven Dependencies"目 ...
- Linux 删除文件夹
inux删除目录很简单,很多人还是习惯用rmdir 1.直接rm就可以了:rm -rf 目录名字 -r 就是向下递归,不管有多少级目录,一并删除-f 就是直接强行删除,不作任何提示的意思
- socket.io 实例
//引用 var io = require('socket.io')(server); //server io.on('connection', function(socket) { // ...
- KTV2
自制KTV点歌系统经验 重唱与切歌 1.重唱 这个简单,会了播放,就会了这个; 我们用的数组下标来确定播放歌曲,自然如果下标没变的话,那播放的就还是这首了.所以只要确定了要执行的命令是重唱就行了. 那 ...
- hdoj 1892(二维树状数组)
Problem H Time Limit : 5000/3000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other) Total Sub ...