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 8592659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:48:12+00:00 2026-06-11T23:48:12+00:00

In Java, when I supply a floating point variable to printf or String.format ,

  • 0

In Java, when I supply a floating point variable to printf or String.format, it gives nothing. To illustrate, an example:

public class test {
    public static void main(String arg[]) {
        double d = 123.456; 
        System.out.println("println: " + d + " " + (int) d);
        System.out.printf("printf as int: %d%n", (int) d);
        System.out.printf("printf with %%f: %f%n", d);
        System.out.printf("printf with %%e: %e%n", d);
        System.out.printf("printf with %%g: %g%n", d);
        System.out.printf("printf with %%a: %a%n", d);
    }
}

gives

in println: 123.456 123
in printf as int: 123
in printf with %f: 
in printf with %e: 
in printf with %g: 
in printf with %a:

as You can see, it does work with println, but it fails on printf. Same goes with String.format. If I supply width and precision, it does the same – gives nothing.

What am I doing wrong?

EDIT:
I am using en_US.UTF-8 locale;
I am not sure what version of Java I am using. What I know is: I compile it with gcc (gcj), version 4.7.2; And Have gcj JRE version 4.7.2 and OpenJDK JRE version 7u7-2.3.2a installed.;
Edited the code. Now it is the whole code of the program. I wrote it as a small test program after I noticed these problems with floating point numbers in my other code.

  • 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-06-11T23:48:13+00:00Added an answer on June 11, 2026 at 11:48 pm

    There is a good chance it’s a bug in GCJ. See here: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=561685

    Get rid of GCJ and use OpenJDK or Sun/OracleJDK.

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

Sidebar

Related Questions

Java Message Service book by O'Reilly Media says: use request/reply model in point-to-point messaging.
I'm writing a method that forms part of the public interface of a Java
In Java 6, my understanding is that you can supply a Comparator to a
I want to pass the string !changeme! to a java program on the command
Is there a best practice for enumerations in java? For example, I have the
Java 7 is supposed to fix an old problem with unpacking zip archives with
JAVA : is there a difference between the two references p && pp? PrintStream
Java allows for certain keywords to be followed by a statement or a statement
Java noob question: Consider the following C array and initializer code: struct { int
Java Internationalization Rules . It says to replace s1.compareTo(s)==0 with Collator.compare(s1,s2)<0 why <0 ?

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.