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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:20:41+00:00 2026-06-11T17:20:41+00:00

Possible Duplicate: Is there an equivalent for toPrecision() in Java? I created a method

  • 0

Possible Duplicate:
Is there an equivalent for toPrecision() in Java?

I created a method which suppose to limit the number to only 2 decimal places but what it does it shows numbers to 2 decimal places and then display zeros after that.

Also, from the number computation below I can notice that it rounds the numbers incorrectly. The numbers should be 478.03 129.06 348.97.

What’s wrong here?

PS. I’m just following pseudocode and I can’t import anything more than import java.io.*;

My output:

Employee's Last Name: dfsdfsdf
Employment Status (F or P): p
Hourly Pay Rate: 8.35
Hours Worked: 51.5
-------------------------------------------------------
Name    Status      Gross   Taxes   Net
dfsdfsdf    Part Time       478.040000  129.070000  348.970000

My code where I input all data, and then attempting to output it:

private static void outputData(String name, char status, double pay) 
{
    if (status == "p".charAt(0))
    {
        System.out.println("-------------------------------------------------------");
        System.out.println("Name\tStatus\t\tGross\tTaxes\tNet");
        System.out.printf("%s\tPart Time\t\t%f\t%f\t%f\n\n", 
                name, 
                roundDouble(pay), 
                roundDouble(calculateTaxes(pay)), 
                roundDouble(pay - calculateTaxes(pay)));
    }
    else if (status == "f".charAt(0))
    {
        System.out.println("-------------------------------------------------------");
    }
}

More code which is the method that should do conversion:

private static double roundDouble(double number) 
{
    return Double.parseDouble(String.format("%.2f", number));
}
  • 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-11T17:20:42+00:00Added an answer on June 11, 2026 at 5:20 pm

    try to do it like this:

    private static double roundDouble(double number) 
    {
        return java.lang.Math.round((number * 100) / 100.0));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Is it possible to define enumalpha? Is there any equivalent of Java
Possible Duplicate: Is there an equivalent of ‘which’ on windows? Failed to find it
Possible Duplicate: How to convert decimal to hex in JavaScript? Is there an equivalent
Possible Duplicate: C# - Programmatic equivalent of default(Type) Is there a method or property
Possible Duplicate: Java equivalent to #region in c# Is there something in Java that
Possible Duplicate: What is the Java equivalent for LINQ? There are numerous questions asking
Possible Duplicate: Is there a difference between single and double quotes in Java? I've
Possible Duplicate: Is there a VB.NET equivalent for C#'s ?? operator? Is there an
Possible Duplicate: Is a Java static block equivalent to a C# static constructor? Is
Possible Duplicate: Is there an equivalent to Trac written in PHP? Are there any

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.