String.format Tutorial
String format(String format, Object... args)
The format specifiers for general, character, and numeric types have the following syntax:
%[argument_index$][flags][width][.precision]conversion
- argument_index is a decimal integer indicating the position of the argument in the argument list. It starts from "1$".
- flags is a set of characters that modify the output format.
| Flag | General | Character | Integer | Floating Point | Date/Time | Description |
| '-' | Y | Y | Y | Y | Y | The result will be left-justified |
| '#' | Y | - | Y | Y | - | The result should use a conversion-dependent alternate form |
| '+' | - | - | Y | Y | - | The result will always include a sign |
| ' ' | - | - | Y | Y | - | The result will include a leading space for positive values |
| '0' | - | - | Y | Y | - | The result will be zero-padded |
| ',' | - | - | Y | Y | - | The result will include locale-specific grouping separators |
| '(' | - | - | Y | Y | - | The result will enclose negative numbers in parentheses |
- width is a non-negative decimal interger indicating the minimum number of the number of characters to be written to the output.
- For the floating-point conversions
'e','E', and'f'the precision is the number of digits after the decimal separator. If the conversion is'g'or'G', then the precision is the total number of digits in the resulting magnitude after rounding. If the conversion is'a'or'A', then the precision must not be specified. - conversion are divided into the following categories:
General, Character, Numeric(Integer, Floating Point), Date/Time, Percent, Line Separator
| Conversion | Argument Category | Description |
|---|---|---|
'b', 'B' |
general | If the argument arg is null, then the result is "false". If arg is a boolean or Boolean, then the result is the string returned by String.valueOf(arg). Otherwise, the result is "true". |
'h', 'H' |
general | If the argument arg is null, then the result is "null". Otherwise, the result is obtained by invoking Integer.toHexString(arg.hashCode()). |
's', 'S' |
general | If the argument arg is null, then the result is "null". If arg implements Formattable, then arg.formatTo is invoked. Otherwise, the result is obtained by invokingarg.toString(). |
'c', 'C' |
character | The result is a Unicode character |
'd' |
integral | The result is formatted as a decimal integer |
'o' |
integral | The result is formatted as an octal integer |
'x', 'X' |
integral | The result is formatted as a hexadecimal integer |
'e', 'E' |
floating point | The result is formatted as a decimal number in computerized scientific notation |
'f' |
floating point | The result is formatted as a decimal number |
'g', 'G' |
floating point | The result is formatted using computerized scientific notation or decimal format, depending on the precision and the value after rounding. |
'a', 'A' |
floating point | The result is formatted as a hexadecimal floating-point number with a significand and an exponent |
't', 'T' |
date/time | Prefix for date and time conversion characters. See Date/Time Conversions. |
'%' |
percent | The result is a literal '%' ('\u0025') |
'n' |
line separator | The result is the platform-specific line separator |
String.format Tutorial的更多相关文章
- c# 字符串连接使用“+”和string.format格式化两种方式
参考文章:http://www.liangshunet.com/ca/201303/218815742.htm 字符串之间的连接常用的两种是:“+”连接.string.format格式化连接.Stri ...
- 【转】string.Format对C#字符串格式化
转自:http://blog.csdn.net/samsone/article/details/7556781 1.格式化货币(跟系统的环境有关,中文系统默认格式化人民币,英文系统格式化美元) str ...
- C#中string.format用法详解
C#中string.format用法详解 本文实例总结了C#中string.format用法.分享给大家供大家参考.具体分析如下: String.Format 方法的几种定义: String.Form ...
- string.Format格式化用法详解
1.格式化货币(跟系统的环境有关,中文系统默认格式化人民币,英文系统格式化美元) string.Format("{0:C}",0.2) 结果为:¥0.20 (英文操作系统结果:$0 ...
- Js实现string.format
经常需要动态拼接html字符串,想到用类似于.net的string.format函数比较好,于是找了下,stackoverflow的代码: if (!String.prototype.format) ...
- String.Format用法
http://blog.csdn.net/yohop/article/details/2534907 1.作为参数 名称 说明 Format(String, Object) 将指定的 Stri ...
- String.Format 格式说明
C#格式化数值结果表 字符 说明 示例 输出 C 货币 string.Format("{0:C3}", 2) $2.000 D 十进制 string.Format("{0 ...
- C# String.Format格式化json字符串中包含"{" "}"报错问题
json.Append(String.Format("{\"total\":{0},\"row\":{1}}", lineCount, st ...
- JAVA字符串格式化-String.format()的使用
String类的format()方法用于创建格式化的字符串以及连接多个字符串对象.熟悉C语言的同学应该记得C语言的sprintf()方法,两者有类似之处.format()方法有两种重载形式. form ...
随机推荐
- sqlserver2005重新安装(安装汇编错误,安装程序无法连接到数据库服务进行服务配置)
2014-01-09 16:41 1687人阅读 评论(1) 收藏 举报 分类: 数据库(1) 版权声明:本文为博主原创文章,未经博主允许不得转载. sqlserver2005重新安装(安装汇编错误, ...
- 简单数据结构———AVL树
C - 万恶的二叉树 Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:32768KB 64b ...
- C#串口扫描
1.传入serialport 和待显示串口的Commbox private void Search_AddSerialToComboBox(SerialPort MyPort, ComboBox My ...
- 自动生成代码工具【JAVA版】
发现任何项目无非五类操作:新增.修改.删除.查询详细.查询列表 大多数的服务端基础代码都是相同的,但是每次开发一个新项目都会做很多重复工作,从controller,bean,service,到数据库访 ...
- nginx对于Yii2的前后台的配置
虽然是个基础问题,但也折腾了不少时间,记录下来,希望对新手有所帮助.例如我的前台地址yooao.cc,后台地址back.yooao.cc back.yooao.cc是yooao.cc的一个子域名. ...
- 判断div是否隐藏
<script type="text/javascript" src="../js/jquery-1.7.2.min.js"></script ...
- TypeScript环境搭建
环境搭建 本篇将简单介绍一下TypeScript,并记录开发环境的搭建.使用Visual Studio Code进行一个简单的Demo开发过程. 第一部分.简介 TypeScript是一种由微软开发的 ...
- jquery中ajax的dataType属性包括哪几项
参考ajax api文档:http://www.w3school.com.cn/jquery/ajax_ajax.asp dataType类型:String预期服务器返回的数据类型.如果不指定,jQu ...
- 使用PULL方式解析XML资源文件下面的xml文件
public class MainActivity extends Activity { private Button btn = null; private List<Map<Strin ...
- Codeforces 358D Dima and Hares
http://codeforces.com/contest/358/problem/D 题意:给出n个数,每个数取走的贡献与相邻的数有关,如果取这个数的时候,左右的数都还没被取,那么权值为a,如果左右 ...