Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How can I get my Java code to print out 2 decimal places instead of 1? I can attach my code if necessary. I have

How can I get my Java code to print out 2 decimal places instead of 1? I can attach my code if necessary. I have a program that collects a peron's name, id number, how much they make an hour, and how long they worked. The system then prints out their information as:

first and last name, employee id ####, made $###.## in gross pay.

I have everything working but when it prints out that information it uses only 1 decimal place.

part of my code:

// this is my function to calculate the amount of money made.

public double grossPay() { return hours * rate; }

**********************************************************************

then in the main method I declared all my other variables including:

double grossPay;

after declaring my variables, I have the system ask the user for their input.

and this is what I have for it to display back to the user:

System.out.println(pay.getName() + ", Employee Number: " + pay.getIdNumbers() + ", made $" + pay.grossPay() + " in gross pay.");

* How can I get the pay.grossPay() to display in 2 decimal places?

the question states to use text forming so that the gross pay is rounded to two decimal places.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions

Question

2. What type of team would you recommend?

Answered: 1 week ago