@@ -0,0 +1,1707 @@
+package com.levelup.java.number;%0A%0Aimport static org.junit.Assert.assertEquals;%0A%0Aimport java.math.RoundingMode;%0Aimport java.text.DecimalFormat;%0A%0Aimport org.junit.Test;%0A%0A/**%0A * This java example will demonstrate a few different ways%0A * to format a decimal using %7B@link DecimalFormat%7D.  Look %0A * further at java's special pattern characters.%0A * %0A * @author Justin Musgrove%0A * @see %3Ca href='http://www.leveluplunch.com//'%3E%3C/a%3E%0A */%0Apublic class FormatDecimal %7B%0A%0A%09@Test%0A%09public void format_decimal_with_rounding_mode () %7B%0A%09%09%0A%09%09double hdTv = 1229.99;%0A%09%09%0A%09%09DecimalFormat df = new DecimalFormat(%22###,###%22);%0A%09%09df.setRoundingMode(RoundingMode.HALF_UP);%0A%09%09%0A%09%09assertEquals(%221,230%22, df.format(hdTv));%0A%09%7D%0A%09%0A%09@Test%0A%09public void format_with_trailing_zeros () %7B%0A%09%09%0A%09%09double singAlongMic = 49;%0A%09%09%0A%09%09DecimalFormat df = new DecimalFormat(%2200.00%22);%0A%09%09%0A%09%09assertEquals(%2249.00%22, df.format(singAlongMic));%0A%09%7D%0A%09%0A%09@Test%0A%09public void format_with_leading_zeros () %7B%0A%09%09%0A%09%09double videoGame = 49;%0A%09%09%0A%09%09DecimalFormat df = new DecimalFormat(%22000,000%22);%0A%09%09%0A%09%09assertEquals(%22000,049%22, df.format(videoGame));%0A%09%7D%0A%09%0A%09@Test%0A%09public void format_decimal_with_commas () %7B%0A%09%09%0A%09%09double expensiveLegos = 1244444;%0A%0A%09%09DecimalFormat df = new DecimalFormat(%22###,###%22);%0A%09%09%0A%09%09assertEquals(%221,244,444%22, df.format(expensiveLegos));%0A%09%7D%0A%09%0A%09%0A%09@Test %0A%09public void format_decimal_with_dollar_sign_currency () %7B%0A%09%09%0A%09%09double blackFridayTVDeal = 120.9;%0A%09%09%0A%09%09DecimalFormat df = new DecimalFormat(%22$#.00%22);%0A%09%09%0A%09%09assertEquals(%22$120.90%22, df.format(blackFridayTVDeal));%0A%09%7D%0A%09%0A%09@Test%0A%09public void format_decimal_with_optional_zero () %7B%0A%09%09%0A%09%09double gameConsole = 229.90;%0A%0A%09%09DecimalFormat df = new DecimalFormat(%22#.##%22);%0A%09%09%0A%09%09assertEquals(%22229.9%22, df.format(gameConsole));%0A%09%7D%0A%09%0A%7D%0A

format decimal