Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>import java.text.DecimalFormat; public class Asdf { public static void main(String[] args) { DecimalFormat format = new DecimalFormat(); format.setDecimalSeparatorAlwaysShown(false); Double asdf = 2.0; Double asdf2 = 2.11; Double asdf3 = 2000.11; System.out.println( format.format(asdf) ); System.out.println( format.format(asdf2) ); System.out.println( format.format(asdf3) ); } } </code></pre> <p>prints:</p> <pre><code>2 2.11 2,000.11 </code></pre> <p>Using </p> <pre><code>DecimalFormat format=new DecimalFormat("#.#"); //not okay!!! </code></pre> <p>is not right as it messes with 10^3, 10^6, etc. separators.</p> <p>2000.11 would be displayed as "2000.11" instead of "2,000.11"</p> <p>This is of course if you want to display numbers properly formatted, not just using improper toString().</p> <p>Also note, that formatting may different based on users Locale and DecimalFormat should be initialized accordingly using a factory method with user's Locale as an argument:</p> <pre><code>NumberFormat f = NumberFormat.getInstance(loc); if (f instanceof DecimalFormat) { ((DecimalFormat) f).setDecimalSeparatorAlwaysShown(true); } </code></pre> <p><a href="http://download.oracle.com/javase/1.5.0/docs/api/java/text/DecimalFormat.html">http://download.oracle.com/javase/1.5.0/docs/api/java/text/DecimalFormat.html</a></p> <p><strong>UPDATE</strong> This formatting string works fine also without calling the extra method:</p> <pre><code> DecimalFormat format=new DecimalFormat("#,###.#"); //format.setDecimalSeparatorAlwaysShown(false); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload