QMCS 230 - PowerPoint PPT Presentation

1 / 7
About This Presentation
Title:

QMCS 230

Description:

0.00' = commas, always one digit to ... ASK ONLY ONCE. Remember the decision. If not authorized, pay for first 8 hours ... Creative Commons License ... – PowerPoint PPT presentation

Number of Views:13
Avg rating:3.0/5.0
Slides: 8
Provided by: ricks6
Category:
Tags: qmcs | license

less

Transcript and Presenter's Notes

Title: QMCS 230


1
QMCS 230 Today in Class
  • Getting Homework Back
  • DecimalFormat class - recap
  • the printf method
  • Revision to Payroll - Lab 6

2
DecimalFormat class
  • Convert numbers into strings NICELY
  • Control decimal appearance
  • Insert commas, force/suppress leading 0s
  • import java.text.DecimalFormat
  • DecimalFormat twoDecimals
  • new DecimalFormat(0.00)

3
Decimal Format Options
  • 0 where you ALWAYS want a digit
  • Digits to the right indicate rounding
  • . Decimal point, if any
  • Optional leading digit
  • , Comma, like between 3 0s
  • ,0.00 commas, always one digit to
  • the left of the decimal, exactly 2 digits to the
    right of the decimal
  • at end makes percentage (x100)
  • Lets do an example

4
the printf method
  • A variant of println that does formatting
  • Descended from an ill-behaved Unix feature
  • I only like it because
  • I know it
  • Its easy to use
  • Bad thing it only works on output
  • DecimalFormat works for all strings

5
The printf secret code
  • Make a text string
  • Embed a code for each number inserted
  • d integer decimal
  • s string
  • f double floating point
  • Leading digit spaces to use
  • Comma insert commas in a number
  • Decimal followed by digit decimal places

6
Revision to Payroll
  • Pick a version (Scanner version is best)
  • If theres any overtime, ask for authorization
  • ASK ONLY ONCE
  • Remember the decision
  • If not authorized, pay for first 8 hours
  • Format the numbers nicely
  • Calculate to cents
  • Suppress ill-behaved decimal points

7
Creative Commons License
  • This work is licensed under the Creative Commons
    Attribution-Share Alike 3.0 United States
    License. To view a copy of this license, visit
    http//creativecommons.org/licenses/by-sa/3.0/us/
    or send a letter to Creative Commons, 171 Second
    Street, Suite 300, San Francisco, California,
    94105, USA.
Write a Comment
User Comments (0)
About PowerShow.com