: MIDRANGE dot COM Mailing List Archive

Re: Decimal rounding of a float data type in Java.


AddThis Feed Button



Here's an example of displaying decimal value:



DecimalFormat   twoDigits = new  DecimalFormat( " 0.00" );

if ( gradeCounter != 0 ) {
     average = total / gradeCounter;

// display output here
JOptionPane.showMessageDialog( null,
    "Average is  " + twoDigits.format( average ), " Average ",
JOptionPane.INFORMATION_MESSAGE );
}

the first statement declares  twoDigits as a reference to an object of
class DecimalFormat.

DecimalFormat objects are used to format number.  In this example we want
to output the variable average with two  digits to the right of the decimal
point.

+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---



Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2007 by MIDRANGE dot COM and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available here. If you have questions about this, please contact

.

counter