Tuesday, 23 February 2016

Java Tutorial : Java format (DecimalFormat class)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=SiPUuR5UQpU&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java format (DecimalFormat class) 
Java Tutorial : Java format (DecimalFormat class) 
DecimalFormatDemo.java
import java.text.DecimalFormat;

public class DecimalFormatDemo
{

    static public void customFormat(String pattern, double value)
    {
        DecimalFormat myFormatter = new DecimalFormat(pattern);
        String output = myFormatter.format(value);
        System.out.println(value + "  " + pattern + "  " + output);
    }

    static public void main(String[] args)
    {

        customFormat("###,###.###", 123456.789);
        customFormat("###.##", 123456.789);
        customFormat("000000.000", 123.78);
        customFormat("$###,###.###", 12345.67);
    }
}
Output
123456.789  ###,###.###  123,456.789
123456.789  ###.##  123456.79
123.78  000000.000  000123.780
12345.67  $###,###.###  $12,345.67
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/FormatDemo_DecimalFormat_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/FormatDemo_DecimalFormat_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/9880b82016e29094f797cfa7ceb03441b567b426/BasicJava/FormatDemo_DecimalFormat_App/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge