1 / 7

QMCS 230 – Today in Class

QMCS 230 – Today in Class. Getting Homework Back DecimalFormat class - recap the printf method Revision to Payroll - Lab 6. DecimalFormat class. Convert numbers into strings NICELY Control decimal appearance Insert commas, force/suppress leading 0s import java.text.DecimalFormat;

scott
Download Presentation

QMCS 230 – Today in Class

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. QMCS 230 – Today in Class • Getting Homework Back • DecimalFormat class - recap • the printf method • Revision to Payroll - Lab 6 R. Smith - University of St Thomas - Minnesota

  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”); R. Smith - University of St Thomas - Minnesota

  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) • Let’s do an example R. Smith - University of St Thomas - Minnesota

  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 • It’s easy to use • Bad thing – it only works on output • DecimalFormat works for all strings R. Smith - University of St Thomas - Minnesota

  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 R. Smith - University of St Thomas - Minnesota

  6. Revision to Payroll • Pick a version (Scanner version is best) • If there’s 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 R. Smith - University of St Thomas - Minnesota

  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. R. Smith - University of St Thomas - Minnesota

More Related