Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does a hash/pound (#) represent in a format string?

I have some code to format a file size string:

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

Is the @"#,##0.## bytes" the same kind of format string as I'd use in stringWithFormat? What do the hash/pound symbols mean here?

like image 263
nevan king Avatar asked Jul 11 '26 10:07

nevan king


1 Answers

# will usually be replaced by a number if one exists, and nothing if it doesn't. 0 will be replaced by a number if one exists, and zero if it does not.

So for the following formatting '##00.00##' you would get the following outputs:

1 => 01.00
12.1 => 12.10
1234.5 => 1234.50
1.2345 => 01.2345
like image 54
samjudson Avatar answered Jul 14 '26 00:07

samjudson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!