timemanx
timemanx

Reputation: 4523

What does 1.f mean

While going through a class I saw 1.f assigned as a value to a float variable. What is the use of the . here? How is this different from just 1f?

Upvotes: 4

Views: 4836

Answers (3)

WaughWaugh
WaughWaugh

Reputation: 1032

You can express a float literal as '1.'(excluding the quotes). This will mean exactly the same as 1.0. So, here 1.f means actually 1.0f.

Upvotes: 1

Kevin Workman
Kevin Workman

Reputation: 42176

It's not different at all.

1.f is the same as 1.0f or 1.00000000f or 1f.

Upvotes: 1

NPE
NPE

Reputation: 500317

It's exactly the same as 1f and means the number 1.0 expressed as a float literal. Other ways to express the same literal include 1.0f, +1.00000f, 1e0f, 1.e+0f and so on.

For a detailed specification, see §3.10.2. Floating-Point Literals in the JLS.

Upvotes: 9

Related Questions