Java DecimalFormat: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
No edit summary
Line 13: Line 13:
<font color=red>'#' means display the digit if ? It does not fill up with space.</font>
<font color=red>'#' means display the digit if ? It does not fill up with space.</font>


!!!Simplest
=Simplest=


{{{
<pre>
    
    
     private static final Format THREAD_NUMBER_FORMAT = new DecimalFormat("000");
     private static final Format THREAD_NUMBER_FORMAT = new DecimalFormat("000");
Line 23: Line 23:
     THREAD_NUMBER_FORMAT.format(index);
     THREAD_NUMBER_FORMAT.format(index);


}}}
</pre>


!!!Float/Double with Two Decimals
=Float/Double with Two Decimals=
 
<pre>


{{{
     private static final Format AVERAGE_DURATION_FORMAT = new DecimalFormat("#.00");
     private static final Format AVERAGE_DURATION_FORMAT = new DecimalFormat("#.00");


Line 34: Line 35:
     AVERAGE_DURATION_FORMAT.format(value);
     AVERAGE_DURATION_FORMAT.format(value);


}}}
</pre>
 
__Referenced by:__\\
[{INSERT com.ecyrd.jspwiki.plugin.ReferringPagesPlugin WHERE max=20, maxwidth=50}]

Revision as of 18:03, 22 January 2016

External

Internal

Overview

'#' means display the digit if ? It does not fill up with space.

Simplest

   
    private static final Format THREAD_NUMBER_FORMAT = new DecimalFormat("000");

    ...

    THREAD_NUMBER_FORMAT.format(index);

Float/Double with Two Decimals


    private static final Format AVERAGE_DURATION_FORMAT = new DecimalFormat("#.00");

    ...

    AVERAGE_DURATION_FORMAT.format(value);