Ranganath Kini wrote:
> Hi,
>
> Please consider using the java.text.DecimalFormat class to format your
> decimal output. Here is an example:
>
> import java.text.DecimalFormat;
>
> public class NumberFormat {
> public static void main( String[] args ) {
> double value = 5.94;
> DecimalFormat df = new DecimalFormat( "##.##" );
> System.out.println( "The value is: " + df.format( value ) );
> }
> }
>
> java.text.DecimalFormat class formats the output based on a wildcard
> pattern that you feed it. These wild cards are:
>
> # - for a digit, does not show 0 if last
> 0 - for a digit
> . - for the decimal separator
> - - the minus sign
> , - grouping separator
> E - for scientific notation
> % - shows as percentage
>
> And there are many more. Please see the JavaDocs on
> java.text.DecimalFormat for more information:
>
> http://java.sun.com/j2se/1.5.0/docs/...malFormat.html
>
> If you want control over the rounding of the numbers during
> computations, then consider using the java.math.BigDecimal class.
Thanks for the tips. Does that mean the format mehtod of Decimal Format
does do rounding?
>
> Hope it helps!
Thanks for the detail explanation. I did figure out soon after my last
post.