ÿØÿà JFIF    ÿÛ „  ( %!1!%)+//.383,7(-.+  -%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ  ¥2" ÿÄ     ÿÄ J    ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ   ÿÄ *  !1AQa‘"2q3±ð#b¡ÿÚ   ? ¼QxJQaÍuò¸Zö Úü8,ÐÚú "SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁT­ÃÛ5 ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßw­pŽF|È¥ù®häðÍѶ¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e ríV ?> ......................................... ............................................................................. ÿØÿà JFIF    ÿÛ „  ( %!1!%)+//.383,7(-.+  -%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ  ¥2" ÿÄ     ÿÄ J    ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ   ÿÄ *  !1AQa‘"2q3±ð#b¡ÿÚ   ? ¼QxJQaÍuò¸Zö Úü8,ÐÚú "SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁT­ÃÛ5 ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßw­pŽF|È¥ù®häðÍѶ¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e ríV ?> ......................................... ............................................................................. ???????????????????????????????????? ???????????????????????????????????? ÿØÿà JFIF    ÿÛ „  ( %!1!%)+//.383,7(-.+  -%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ  ¥2" ÿÄ     ÿÄ J    ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ   ÿÄ *  !1AQa‘"2q3±ð#b¡ÿÚ   ? ¼QxJQaÍuò¸Zö Úü8,ÐÚú "SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁT­ÃÛ5 ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßw­pŽF|È¥ù®häðÍѶ¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e ríV ?> ......................................... ............................................................................. ÿØÿà JFIF    ÿÛ „  ( %!1!%)+//.383,7(-.+  -%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ  ¥2" ÿÄ     ÿÄ J    ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ   ÿÄ *  !1AQa‘"2q3±ð#b¡ÿÚ   ? ¼QxJQaÍuò¸Zö Úü8,ÐÚú "SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁT­ÃÛ5 ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßw­pŽF|È¥ù®häðÍѶ¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e ríV ?> ......................................... ............................................................................. ???????????????????????????????????? ???????????????????????????????????? U:RDoc::TopLevel[ iI"format_specifications.rdoc:ETcRDoc::Parser::Simpleo:RDoc::Markup::Document: @parts[S:RDoc::Markup::Heading: leveli: textI"Format Specifications;To:RDoc::Markup::BlankLineo:RDoc::Markup::Paragraph;[I"JSeveral Ruby core classes have instance method +printf+ or +sprintf+:;T@ o:RDoc::Markup::List: @type: BULLET: @items[ o:RDoc::Markup::ListItem: @label0;[o; ;[I"ARGF#printf;To;;0;[o; ;[I"IO#printf;To;;0;[o; ;[I"Kernel#printf;To;;0;[o; ;[I"Kernel#sprintf;T@ o; ;[I"!Each of these methods takes:;T@ o;;;;[o;;0;[o; ;[I"6Argument +format_string+, which has zero or more ;TI"4embedded _format_ _specifications_ (see below).;To;;0;[o; ;[I"SArguments *arguments, which are zero or more objects to be formatted.;T@ o; ;[ I"8Each of these methods prints or returns the string ;TI"#resulting from replacing each ;TI"Iformat specification embedded in +format_string+ with a string form ;TI"5of the corresponding argument among +arguments+.;T@ o; ;[I"A simple example:;T@ o:RDoc::Markup::Verbatim;[I"Isprintf('Name: %s; value: %d', 'Foo', 0) # => "Name: Foo; value: 0" ;T: @format0o; ;[I")A format specification has the form:;T@ o;;[I"%%[flags][width][.precision]type ;T;0o; ;[I"It consists of:;T@ o;;;;[ o;;0;[o; ;[I"!A leading percent character.;To;;0;[o; ;[I"0Zero or more _flags_ (each is a character).;To;;0;[o; ;[I"2An optional _width_ _specifier_ (an integer).;To;;0;[o; ;[I"WAn optional _precision_ _specifier_ (a period followed by a non-negative integer).;To;;0;[o; ;[I"(A _type_ _specifier_ (a character).;T@ o; ;[I"/Except for the leading percent character, ;TI"Ithe only required part is the type specifier, so we begin with that.;T@ S; ; i; I"Type Specifiers;T@ o; ;[I"GThis section provides a brief explanation of each type specifier. ;TI"0The links lead to the details and examples.;T@ S; ; i; I"\Integer Type Specifiers;T@ o;;;;[ o;;0;[o; ;[I"8+b+ or +B+: Format +argument+ as a binary integer. ;TI"VSee {Specifiers b and B}[rdoc-ref:format_specifications.rdoc@Specifiers+b+and+B].;To;;0;[o; ;[I"++d+, +i+, or +u+ (all are identical): ;TI"-Format +argument+ as a decimal integer. ;TI"HSee {Specifier d}[rdoc-ref:format_specifications.rdoc@Specifier+d].;To;;0;[o; ;[I"1+o+: Format +argument+ as an octal integer. ;TI"HSee {Specifier o}[rdoc-ref:format_specifications.rdoc@Specifier+o].;To;;0;[o; ;[I"=+x+ or +X+: Format +argument+ as a hexadecimal integer. ;TI"VSee {Specifiers x and X}[rdoc-ref:format_specifications.rdoc@Specifiers+x+and+X].;T@ S; ; i; I"#Floating-Point Type Specifiers;T@ o;;;;[ o;;0;[o; ;[I"I+a+ or +A+: Format +argument+ as hexadecimal floating-point number. ;TI"VSee {Specifiers a and A}[rdoc-ref:format_specifications.rdoc@Specifiers+a+and+A].;To;;0;[o; ;[I";+e+ or +E+: Format +argument+ in scientific notation. ;TI"VSee {Specifiers e and E}[rdoc-ref:format_specifications.rdoc@Specifiers+e+and+E].;To;;0;[o; ;[I"@+f+: Format +argument+ as a decimal floating-point number. ;TI"HSee {Specifier f}[rdoc-ref:format_specifications.rdoc@Specifier+f].;To;;0;[o; ;[I":+g+ or +G+: Format +argument+ in a "general" format. ;TI"VSee {Specifiers g and G}[rdoc-ref:format_specifications.rdoc@Specifiers+g+and+G].;T@ S; ; i; I"Other Type Specifiers;T@ o;;;;[ o;;0;[o; ;[I",+c+: Format +argument+ as a character. ;TI"HSee {Specifier c}[rdoc-ref:format_specifications.rdoc@Specifier+c].;To;;0;[o; ;[I"G+p+: Format +argument+ as a string via argument.inspect. ;TI"HSee {Specifier p}[rdoc-ref:format_specifications.rdoc@Specifier+p].;To;;0;[o; ;[I"D+s+: Format +argument+ as a string via argument.to_s. ;TI"HSee {Specifier s}[rdoc-ref:format_specifications.rdoc@Specifier+s].;To;;0;[o; ;[I"Q%: Format +argument+ ('%') as a single percent character. ;TI"JSee {Specifier %}[rdoc-ref:format_specifications.rdoc@Specifier+-25].;T@ S; ; i; I" Flags;T@ o; ;[I"BThe effect of a flag may vary greatly among type specifiers. ;TI"*These remarks are general in nature. ;TI"jSee {type-specific details}[rdoc-ref:format_specifications.rdoc@Type+Specifier+Details+and+Examples].;T@ o; ;[I"=Multiple flags may be given with single type specifier; ;TI"order does not matter.;T@ S; ; i; I"' ' Flag;T@ o; ;[I"1Insert a space before a non-negative number:;T@ o;;[I""sprintf('%d', 10) # => "10" ;TI"#sprintf('% d', 10) # => " 10" ;T;0o; ;[I",Insert a minus sign for negative value:;T@ o;;[I"$sprintf('%d', -10) # => "-10" ;TI"$sprintf('% d', -10) # => "-10" ;T;0S; ; i; I"'#' Flag;T@ o; ;[I"1Use an alternate format; varies among types:;T@ o;;[I"#sprintf('%x', 100) # => "64" ;TI"%sprintf('%#x', 100) # => "0x64" ;T;0S; ; i; I"'+' Flag;T@ o; ;[I"7Add a leading plus sign for a non-negative number:;T@ o;;[I"#sprintf('%x', 100) # => "64" ;TI"$sprintf('%+x', 100) # => "+64" ;T;0S; ; i; I"'-' Flag;T@ o; ;[I")Left justify the value in its field:;T@ o;;[I"(sprintf('%6d', 100) # => " 100" ;TI"(sprintf('%-6d', 100) # => "100 " ;T;0S; ; i; I"'0' Flag;T@ o; ;[I"+Left-pad with zeros instead of spaces:;T@ o;;[I"(sprintf('%6d', 100) # => " 100" ;TI"(sprintf('%06d', 100) # => "000100" ;T;0S; ; i; I"'*' Flag;T@ o; ;[I".Use the next argument as the field width:;T@ o;;[I"&sprintf('%d', 20, 14) # => "20" ;TI"8sprintf('%*d', 20, 14) # => " 14" ;T;0S; ; i; I"'n$' Flag;T@ o; ;[I"@Format the (1-based) nth argument into this field:;T@ o;;[I"?sprintf("%s %s", 'world', 'hello') # => "world hello" ;TI"?sprintf("%2$s %1$s", 'world', 'hello') # => "hello world" ;T;0S; ; i; I"Width Specifier;T@ o; ;[I"PIn general, a width specifier determines the minimum width (in characters) ;TI"of the formatted field:;T@ o;;[ I"-sprintf('%10d', 100) # => " 100" ;TI" ;TI"!# Left-justify if negative. ;TI"-sprintf('%-10d', 100) # => "100 " ;TI" ;TI"# Ignore if too small. ;TI"&sprintf('%1d', 100) # => "100" ;T;0S; ; i; I"Precision Specifier;T@ o; ;[I"GA precision specifier is a decimal point followed by zero or more ;TI"decimal digits.;T@ o; ;[ I"PFor integer type specifiers, the precision specifies the minimum number of ;TI"Wdigits to be written. If the precision is shorter than the integer, the result is ;TI"Upadded with leading zeros. There is no modification or truncation of the result ;TI"1if the integer is longer than the precision:;T@ o;;[ I"&sprintf('%.3d', 1) # => "001" ;TI"'sprintf('%.3d', 1000) # => "1000" ;TI" ;TI"D# If the precision is 0 and the value is 0, nothing is written ;TI" sprintf('%.d', 0) # => "" ;TI" sprintf('%.0d', 0) # => "" ;T;0o; ;[I"KFor the +a+/+A+, +e+/+E+, +f+/+F+ specifiers, the precision specifies ;TI"@the number of digits after the decimal point to be written:;T@ o;;[ I"+sprintf('%.2f', 3.14159) # => "3.14" ;TI"3sprintf('%.10f', 3.14159) # => "3.1415900000" ;TI" ;TI"C# With no precision specifier, defaults to 6-digit precision. ;TI"/sprintf('%f', 3.14159) # => "3.141590" ;T;0o; ;[I"9For the +g+/+G+ specifiers, the precision specifies ;TI"4the number of significant digits to be written:;T@ o;;[ I"-sprintf('%.2g', 123.45) # => "1.2e+02" ;TI")sprintf('%.3g', 123.45) # => "123" ;TI"-sprintf('%.10g', 123.45) # => "123.45" ;TI" ;TI"F# With no precision specifier, defaults to 6 significant digits. ;TI".sprintf('%g', 123.456789) # => "123.457" ;T;0o; ;[I":For the +s+, +p+ specifiers, the precision specifies ;TI"'the number of characters to write:;T@ o;;[I"Asprintf('%s', Time.now) # => "2022-05-04 11:59:16 -0400" ;TI"2sprintf('%.10s', Time.now) # => "2022-05-04" ;T;0S; ; i; I"(Type Specifier Details and Examples;T@ S; ; i; I"Specifiers +a+ and +A+;T@ o; ;[I" "0x1.921f9f01b866ep+1" ;TI";sprintf('%a', -3.14159) # => "-0x1.921f9f01b866ep+1" ;TI"-sprintf('%a', 4096) # => "0x1p+12" ;TI".sprintf('%a', -4096) # => "-0x1p+12" ;TI" ;TI"Q# Capital 'A' means that alphabetical characters are printed in upper case. ;TI"-sprintf('%A', 4096) # => "0X1P+12" ;TI".sprintf('%A', -4096) # => "-0X1P+12" ;T;0S; ; i; I"Specifiers +b+ and +B+;T@ o; ;[I"7The two specifiers +b+ and +B+ behave identically ;TI",except when flag '#'+ is used.;T@ o; ;[I"+Format +argument+ as a binary integer:;T@ o;;[I" sprintf('%b', 1) # => "1" ;TI""sprintf('%b', 4) # => "100" ;TI" ;TI"'# Prefix '..' for negative value. ;TI"$sprintf('%b', -4) # => "..100" ;TI" ;TI"# Alternate format. ;TI"%sprintf('%#b', 4) # => "0b100" ;TI"%sprintf('%#B', 4) # => "0B100" ;T;0S; ; i; I"Specifier +c+;T@ o; ;[I"-Format +argument+ as a single character:;T@ o;;[I"!sprintf('%c', 'A') # => "A" ;TI"!sprintf('%c', 65) # => "A" ;T;0o; ;[I"YThis behaves like String#<<, except for raising ArgumentError instead of RangeError.;T@ S; ; i; I"Specifier +d+;T@ o; ;[I",Format +argument+ as a decimal integer:;T@ o;;[I"$sprintf('%d', 100) # => "100" ;TI"%sprintf('%d', -100) # => "-100" ;T;0o; ;[I"&Flag '#' does not apply.;T@ S; ; i; I"Specifiers +e+ and +E+;T@ o; ;[I"Format +argument+ in ;TI"N{scientific notation}[https://en.wikipedia.org/wiki/Scientific_notation]:;T@ o;;[I"1sprintf('%e', 3.14159) # => "3.141590e+00" ;TI"2sprintf('%E', -3.14159) # => "-3.141590E+00" ;T;0S; ; i; I"Specifier +f+;T@ o; ;[I"2Format +argument+ as a floating-point number:;T@ o;;[I"-sprintf('%f', 3.14159) # => "3.141590" ;TI".sprintf('%f', -3.14159) # => "-3.141590" ;T;0o; ;[I"&Flag '#' does not apply.;T@ S; ; i; I"Specifiers +g+ and +G+;T@ o; ;[I"BFormat +argument+ using exponential form (+e+/+E+ specifier) ;TI"Pif the exponent is less than -4 or greater than or equal to the precision. ;TI"KOtherwise format +argument+ using floating-point form (+f+ specifier):;T@ o;;[I"$sprintf('%g', 100) # => "100" ;TI"&sprintf('%g', 100.0) # => "100" ;TI",sprintf('%g', 3.14159) # => "3.14159" ;TI"/sprintf('%g', 100000000000) # => "1e+11" ;TI"1sprintf('%g', 0.000000000001) # => "1e-12" ;TI" ;TI"*# Capital 'G' means use capital 'E'. ;TI"/sprintf('%G', 100000000000) # => "1E+11" ;TI"1sprintf('%G', 0.000000000001) # => "1E-12" ;TI" ;TI"# Alternate format. ;TI"6sprintf('%#g', 100000000000) # => "1.00000e+11" ;TI"8sprintf('%#g', 0.000000000001) # => "1.00000e-12" ;TI"6sprintf('%#G', 100000000000) # => "1.00000E+11" ;TI"8sprintf('%#G', 0.000000000001) # => "1.00000E-12" ;T;0S; ; i; I"Specifier +o+;T@ o; ;[I",Format +argument+ as an octal integer. ;TI"KIf +argument+ is negative, it will be formatted as a two's complement ;TI"prefixed with +..7+:;T@ o;;[ I"#sprintf('%o', 16) # => "20" ;TI" ;TI"(# Prefix '..7' for negative value. ;TI"&sprintf('%o', -16) # => "..760" ;TI" ;TI"5# Prefix zero for alternate format if positive. ;TI"$sprintf('%#o', 16) # => "020" ;TI"&sprintf('%#o', -16) # => "..760" ;T;0S; ; i; I"Specifier +p+;T@ o; ;[I"AFormat +argument+ as a string via argument.inspect:;T@ o;;[I"t = Time.now ;TI"Asprintf('%p', t) # => "2022-05-01 13:42:07.1645683 -0500" ;T;0S; ; i; I"Specifier +s+;T@ o; ;[I">Format +argument+ as a string via argument.to_s:;T@ o;;[I"t = Time.now ;TI"7sprintf('%s', t) # => "2022-05-01 13:42:07 -0500" ;T;0o; ;[I"&Flag '#' does not apply.;T@ S; ; i; I"Specifiers +x+ and +X+;T@ o; ;[I"1Format +argument+ as a hexadecimal integer. ;TI"KIf +argument+ is negative, it will be formatted as a two's complement ;TI"prefixed with +..f+:;T@ o;;[I"$sprintf('%x', 100) # => "64" ;TI" ;TI"(# Prefix '..f' for negative value. ;TI"'sprintf('%x', -100) # => "..f9c" ;TI" ;TI"# Use alternate format. ;TI"&sprintf('%#x', 100) # => "0x64" ;TI" ;TI",# Alternate format for negative value. ;TI")sprintf('%#x', -100) # => "0x..f9c" ;T;0S; ; i; I"Specifier %;T@ o; ;[I"DFormat +argument+ ('%') as a single percent character:;T@ o;;[I"(sprintf('%d %%', 100) # => "100 %" ;T;0o; ;[I"Flags do not apply.;T@ S; ; i; I"Reference by Name;T@ o; ;[I"EFor more complex formatting, Ruby supports a reference by name. ;TI"A%s style uses format style, but %{name} style doesn't.;T@ o; ;[I"Examples:;T@ o;;[I"Nsprintf("%d : %f", { :foo => 1, :bar => 2 }) # => 1 : 2.000000 ;TI"Esprintf("%{foo}f", { :foo => 1 }) # => "1f";T;0: @file@:0@omit_headings_from_table_of_contents_below0