String格式化参数整理

Java String格式话参数整理如下:

conversion:转换格式,可选的格式有:

d 整数型(十进制)
c Unicode字符
b Boolean值
s String
f 浮点数(十进制)
e 浮点数(科学计数)
x 整数(十六进制)
h 散列码
% 字符串“%”

C++ String格式化参数整理如下:

1.转换说明符
%a(%A)     浮点数、十六进制数字和p-(P-)记数法(C99)
%c         字符
%d         有符号十进制整数
%f         浮点数(包括float和doulbe)
%e(%E)     浮点数指数输出[e-(E-)记数法]
%g(%G)     浮点数不显无意义的零"0"
%i         有符号十进制整数(与%d相同)
%u         无符号十进制整数
%o         八进制整数
%x(%X)     十六进制整数0f(0F)   e.g.   0x1234
%p         指针
%s         字符串
%%         输出字符%

PHP String格式化参数整理如下:

% 印出百分比符号,不转换。
b 整数转成二进位。 
c 整数转成对应的 ASCII 字符。 
d 整数转成十进位。 
f 倍精确度数字转成浮点数。 
o 整数转成八进位。 
s 整数转成字符串。 
x 整数转成小写十六进位。 
X 整数转成大写十六进位。

Python String格式化参数整理如下:

字符串格式化符号
格式化符号    说明
%c    转换成字符(ASCII 码值,或者长度为一的字符串)
%r    优先用repr()函数进行字符串转换(Python2.0新增)
%s    优先用str()函数进行字符串转换
%d / %i     转成有符号十进制数
%u    转成无符号十进制数
%o    转成无符号八进制数
%x / %X    (Unsigned)转成无符号十六进制数(x / X 代表转换后的十六进制字符的大小写)
%e / %E    转成科学计数法(e / E控制输出e / E)
%f / %F    转成浮点数(小数部分自然截断)
%g / %G    %e和%f / %E和%F 的简写
%%    输出%

Javascript String格式化参数整理如下:

原生语言,没有

Node中有sprintf包,见 https://npm.taobao.org/package/sprintf-js

% — yields a literal % character
b — yields an integer as a binary number
c — yields an integer as the character with that ASCII value
d or i — yields an integer as a signed decimal number
e — yields a float using scientific notation
u — yields an integer as an unsigned decimal number
f — yields a float as is; see notes on precision above
g — yields a float as is; see notes on precision above
o — yields an integer as an octal number
s — yields a string as is
x — yields an integer as a hexadecimal number (lower-case)
X — yields an integer as a hexadecimal number (upper-case)
j — yields a JavaScript object or array as a JSON encoded string
原文地址:https://www.cnblogs.com/charlesblc/p/5965897.html