Java konverter tipe data adalah tutorila bagaimana convert tipe data integer ke dalam string double dll..
langsung aja gan .. cekidot..
package Converter;
import java.text.*;
import java.util.*;
public class ConverterRizki {
private Integer bilanganInteger;
private Long bilanganLong;
private String bilanganHexa;
private String bilanganBinary;
private String bilanganOctal;
private double bilanganDouble;
private float bilanganFloat;
private String dateString;
private Date stringDate;
private String outputFormat;
public Integer getBilanganInteger() {
return bilanganInteger;
}
public void setBilanganInteger(Integer bilanganInteger) {
this.bilanganInteger = bilanganInteger;
}
public Long getBilanganLong() {
return bilanganLong;
}
public void setBilanganLong(Long bilanganLong) {
this.bilanganLong = bilanganLong;
}
public String getBilanganHexa() {
return bilanganHexa;
}
public void setBilanganHexa(String bilanganHexa) {
this.bilanganHexa = bilanganHexa;
}
public String getBilanganBinary() {
return bilanganBinary;
}
public void setBilanganBinary(String bilanganBinary) {
this.bilanganBinary = bilanganBinary;
}
public String getBilanganOctal() {
return bilanganOctal;
}
public void setBilanganOctal(String bilanganOctal) {
this.bilanganOctal = bilanganOctal;
}
@Override
public String toString() {
return "String to Integer : "+bilanganInteger+"\nLong to Double : "+
bilanganDouble+"\nLong to Float : "+bilanganFloat+"\nLong to Binary : "+bilanganBinary
+"\nLong to Hexa : "+bilanganHexa+"\nLong To Octal : "+bilanganOctal+
"\nDate to String : "+dateString+"\nTo Decimal Format : "+outputFormat;
}
public void stringToInteger(String string)
{
this.bilanganInteger = Integer.parseInt(string);
}
public void longToDoubleFloat(Long l)
{
this.bilanganDouble = l.doubleValue();
this.bilanganFloat = l.floatValue();
}
public void longToBinerHexaOctal(Long l)
{
this.bilanganBinary = Long.toBinaryString(l);
this.bilanganHexa = Long.toHexString(l);
this.bilanganOctal =Long.toOctalString(l);
}
public void dateToString(Date date, String pattern)
{
DateFormat df = new SimpleDateFormat(pattern);
this.dateString = df.format(date);
}
public void stringToDate(String strDate, String pattern)
throws ParseException {
SimpleDateFormat df = null;
Date date = null;
df = new SimpleDateFormat(pattern);
try {
date = df.parse(strDate);
} catch (ParseException pe) {
throw new ParseException(pe.getMessage(), pe.getErrorOffset());
}
this.stringDate = date;
System.out.println("String to Date :"+df.format(date));
//return (date);
}
public void decimalToFormatDecimal(Double d, String model)
{
DecimalFormat format = new DecimalFormat(model);
this.outputFormat = format.format(d);
}
public static void main(String args[]) throws ParseException
{
ConverterRizki converter = new ConverterRizki();
converter.stringToInteger("12345");
converter.longToDoubleFloat(new Long(123456));
converter.longToBinerHexaOctal(new Long(12345));
Date today = Calendar.getInstance().getTime();
converter.dateToString(today,"MM-dd-yyyy");
converter.decimalToFormatDecimal(new Double(123456.765),"###,###.##");
System.out.println(converter);
converter.stringToDate("01-21-2010","MM-dd-yyyy");
}
}
0 komentar:
Posting Komentar