Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 849035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:02:20+00:00 2026-05-15T07:02:20+00:00

Look at the three lines of code below. float f = 1; float g

  • 0

Look at the three lines of code below.

  float f = 1;

  float g = 1.1;

  float h = 1.1f;

Second line has compilation errors, while the other lines do not have compilation errors. First line is working fine without suffix f and third line is working with suffix f. Why is this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T07:02:21+00:00Added an answer on May 15, 2026 at 7:02 am

    Floating point literals in Java is a double value by default.

    JLS 3.10.2 Floating-Point Literals

    A floating-point literal is of type float if it is suffixed with an ASCII letter F or f; otherwise its type is double and it can optionally be suffixed with an ASCII letter D or d.

    You can’t assign a double value to a float without an explicit narrowing conversion. You therefore have two options:

    • For literals, use the suffix f or F to denote a float value
    • For non-literals, use an explicit cast (float)

    An example of the latter is:

    double d = 1.1;
    float f = (float) d; // compiles fine!
    

    On widening conversions

    The reason why this compiles:

    float f = 1;
    

    is because the widening conversion from int to float can be done implicitly in the context of an assignment.

    JLS 5.2 Assignment Conversion

    Assignment conversion occurs when the value of an expression is assigned to a variable: the type of the expression must be converted to the type of the variable. Assignment contexts allow the use of one of the following:

    • a widening primitive conversion (§5.1.2)
    • […]

    JLS 5.1.2 Widening Primitive Conversion

    The following 19 specific conversions on primitive types are called the widening primitive conversions:

    • int to long, float, or double
    • […]

    Other data type suffix for literals

    As mentioned above, there’s also the D or d suffix for double. Consider this snippet for example:

    static void f(int i) {
        System.out.println("(int)");
    }
    static void f(double d) {
        System.out.println("(double)");
    }
    
    //...
    f(1);   // prints "(int)"
    f(1D);  // prints "(double)"
    

    There’s also a suffix for long literals, which is L or l (lowercase letter). It is highly recommended that you use the uppercase variant.

    JLS 3.10.1 Integer Literals

    An integer literal is of type long if it is suffixed with an ASCII letter L or l (ell); otherwise it is of type int. The suffix L is preferred, because the letter l (ell) is often hard to distinguish from the digit 1 (one).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 542k
  • Answers 542k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use: SELECT p.id as a, p.url as b, t.id as… May 17, 2026 at 3:22 am
  • Editorial Team
    Editorial Team added an answer There are two parts to the problem First Issue You… May 17, 2026 at 3:19 am
  • Editorial Team
    Editorial Team added an answer I thought I'd show the regex approach, too. It doesn't… May 17, 2026 at 3:18 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

8 bits representing the number 7 look like this: 00000111 Three bits are set.
I know you can look at the row.count or tables.count, but are there other
I look around and see some great snippets of code for defining rules, validation,
Hopefully a picture is worth a thousand lines of code because I don't want
We have an application that has one or more text console windows that all
i've created an rss feed in php using the below code. i've double checked
I have the following code which works just fine when the method is POST,
Is there C# look-alike for Linux? What about a compiler?
Is there a command, or a set of tables I can look at to
I haven't had a chance to look at VS2010. Is there a built-in Microsoft

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.