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

  • SEARCH
  • Home
  • 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 7969285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:12:48+00:00 2026-06-04T07:12:48+00:00

The following code: DecimalFormat df = new DecimalFormat(); df.setMinimumFractionDigits(2); int zahl1 = 10; int

  • 0

The following code:

    DecimalFormat df = new DecimalFormat();
    df.setMinimumFractionDigits(2);

    int zahl1 = 10;
    int zahl2 = 18;

    double double1 = zahl1 / zahl2;
    System.out.println("Double1 = " + df.format(double1));

    double double2 = Math.ceil(zahl1 / zahl2);
    System.out.println("Double2 = " + df.format(double2));

    double double3 = Math.round((zahl1 / zahl2) * 100) / 100;
    System.out.println("Double3 = " + df.format(double3));

    float float1 = Math.round((zahl1 / zahl2) * 100) / 100;
    System.out.println("Float1  = " + df.format(float1));

    long long1 = zahl1 / zahl2;
    System.out.println("long1 = " + df.format(long1));

    long long3 = Math.round((zahl1 / zahl2) * 100) / 100;
    System.out.println("long3 = " + df.format(long3));

renders the following output:

Double1 = 0,00
Double2 = 0,00
Double3 = 0,00
Float1  = 0,00
long1 = 0,00
long3 = 0,00

I read quite a bit now about floats and doubles and what not in Java, but I don’t seem to fully understand how to get to my desired outcome of 0.6.

What am I doing wrong?

  • 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-04T07:12:49+00:00Added an answer on June 4, 2026 at 7:12 am

    Since zahl1 and zahl2 are of type int, the following:

    double double1 = zahl1 / zahl2;
    

    uses integer division, the result of which is 0.

    It does not matter that you’re assigning the result to a variable of type double: the (integer) division happens first, and its result is then widened to a double.

    To fix, change that line to:

    double double1 = zahl1 / (double)zahl2;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following code causes a NullReferenceException tStartParameter = String.Format(tStartParameter, tTo, tSubject) tProcess = Process.Start(New
Following code does not work - new Date(2011-10-01) What is the format of specifying
Following code is from my REPL: scala> words.zipWithIndex.filter((x:java.lang.String,index:Int)=>index%2==0) <console>:9: error: type mismatch; found :
Following code ProductPricesDataContext db = new ProductPricesDataContext(); var products = from p in db.Products
How would I convert the following code to C# DecimalFormat form String pattern =
Following code will compile but crash at run time: int main() { try {
Following code always print paths with double slashes: use JSON; use File::Spec; my $installdir
Following code, using python 2.6.6 and MySQLdb 1.2.2 causes Commands out of sync; you
following code for partition #include<iostream> using namespace std; #define maxn 10000 int x[maxn]; void
following code behaves strange (at least for me): int testValue = 1234; this.ConversionTest( testValue

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.