hinterbu
hinterbu

Reputation: 767

What is the difference between %.02f and %.2f?

What is the difference between %.02f and %.2f? From what I understand, whatever number comes after the point, indicates the number of decimal places to be displayed when converting a number to a string. But what does it mean when there are two numbers coming after the point as in %.02?

Upvotes: 2

Views: 8843

Answers (2)

JackyW
JackyW

Reputation: 365

say your value is 101

%f = 101.000000
%.f = 101
%.02f = 101.00

Upvotes: 3

rmaddy
rmaddy

Reputation: 318794

The number after the . is the number of fractional digits to show. 02 and 2 are the same number - 2. The 0 has no special meaning here.

There is no significance to a two digit number over a one digit number after the .. It's just a count. If you had %.10f you would get 10 fractional digits.

None of this is specific to Objective-C. It holds for any language that follows the IEEE printf specification.

Upvotes: 7

Related Questions