zoukankan      html  css  js  c++  java
  • 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

    ConversionArgument CategoryDescription
    '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
  • 相关阅读:
    我和小美的撸码日记(3)之一句话搞定MVC表单页数据绑定与提交
    我和小美的撸码日记--基于MVC+Jqgrid的.Net快速开发框架
    我和小美的撸码日记(2)之第一个基于MVC+Jqgrid的列表页面
    我和小美的撸码日记(1)之软件也需靠脸吃饭,带您做张明星脸(附后台经典框架 DEMO 下载)
    Mysql 下DELETE操作表别名问题
    DynaActionForm(动态ActionForm)的使用
    structs中通过LabelValueBean构建下拉列表
    JavaScript中==和===区别
    JAVA包装类的缓存范围
    JAVA循环迭代中删除或添加集合数据报java.util.ConcurrentModificationException错误
  • 原文地址:https://www.cnblogs.com/leo-cai/p/5797044.html
Copyright © 2011-2022 走看看