What does hash / pound (#) mean in the format string?

I have code for formatting a file size string:

NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; 
[numberFormatter setPositiveFormat: @"#,##0.## bytes"];

Is @"#,##0.## bytes"the same format string as stringWithFormat? What do the hash / pound symbols mean?

+3
source share
4 answers

# is usually replaced by a number if it exists, and nothing if it is not. 0 will be replaced by a number if it exists, and zero if it does not match.

So, for the following formatting '## 00.00 ##' you will get the following results:

1 => 01.00
12.1 => 12.10
1234.5 => 1234.50
1.2345 => 01.2345
+6
source

They are called placeholders.

Placeholders

(#) , . , "$ #, ## 0.00", 76329 , , 76 329,00 . , , . ", 0.00", "#, # 0.00" "#, ## 0.00" . , NSNumberFormatter , , ( ) . - , .

: http://developer.apple.com/documentation/InternetWeb/Reference/WO542Reference/com/webobjects/foundation/NSNumberFormatter.html

+3

'#' , 0 , 0 , .

345.5 :

#,##0.## = 345.5
0,000.00 = 0,345.50
+2

# ' , , "0", ( , / ).

+1

Source: https://habr.com/ru/post/1710231/


All Articles