Example usage for java.text DecimalFormat DecimalFormat

List of usage examples for java.text DecimalFormat DecimalFormat

Introduction

In this page you can find the example usage for java.text DecimalFormat DecimalFormat.

Prototype

public DecimalFormat(String pattern) 

Source Link

Document

Creates a DecimalFormat using the given pattern and the symbols for the default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:edu.umm.radonc.ca_dash.controllers.PieChartController.java

public PieChartController() {
    endDate = new Date();
    this.interval = "";

    GregorianCalendar gc = new GregorianCalendar();
    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
    Map<String, Object> sessionMap = externalContext.getSessionMap();

    if (sessionMap.containsKey("endDate")) {
        endDate = (Date) sessionMap.get("endDate");
    } else {/*  www .  j av a 2 s  .com*/
        endDate = new Date();
        sessionMap.put("endDate", endDate);
    }

    if (sessionMap.containsKey("startDate")) {
        startDate = (Date) sessionMap.get("startDate");
    } else {
        gc.setTime(endDate);
        gc.add(Calendar.MONTH, -1);
        startDate = gc.getTime();
        sessionMap.put("startDate", startDate);
        this.interval = "1m";
    }

    this.df = new SimpleDateFormat("MM/dd/YYYY");
    this.decf = new DecimalFormat("###.###");
    this.decf.setRoundingMode(RoundingMode.HALF_UP);
    this.selectedFacility = new Long(-1);
    this.dstats = new SynchronizedDescriptiveStatistics();
    this.dstatsPerDoc = new TreeMap<>();
    this.dstatsPerRTM = new TreeMap<>();
    this.pieChart = new PieChartModel();

    selectedFilters = "all-tx";
}

From source file:com.skubit.iab.activities.TransactionDetailsActivity.java

@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    this.setContentView(R.layout.activity_transactiondetails);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);// w w w .j a  va 2  s .co  m
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(false);

    getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_arrow_back_black_24dp);

    //  toolbar.setNavigationIcon(R.drawable.ic_action_share);
    mFormat = new DecimalFormat("0.00000000");

    //TextView from = (TextView) this.findViewById(R.id.transactiondetails_from);
    TextView to = (TextView) this.findViewById(R.id.transactiondetails_to);
    TextView notes = (TextView) this.findViewById(R.id.transactiondetails_notes);
    TextView amount = (TextView) this.findViewById(R.id.transactiondetails_amount);
    TextView status = (TextView) this.findViewById(R.id.transactiondetails_status);
    TextView date = (TextView) this.findViewById(R.id.transactiondetails_date);
    TextView label = (TextView) this.findViewById(R.id.transactiondetails_label_amount);
    TextView fee = (TextView) this.findViewById(R.id.transactiondetails_fee);

    ObjectMapper mapper = new ObjectMapper();
    TransactionDto transactionDto = null;
    try {
        transactionDto = mapper.readValue(getIntent().getStringExtra("transaction"), TransactionDto.class);
    } catch (JsonParseException e) {
        e.printStackTrace();
    } catch (JsonMappingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (transactionDto == null) {
        return;
    }

    TransactionType type = transactionDto.getTransactionType();
    label.setText(Utils.transactionToText(type));

    if (TransactionType.SEND.equals(type)) {
        to.setText(transactionDto.getAddress());
    }

    formatStatus(status, transactionDto.getTransactionState());
    formatBalance(amount, transactionDto.getAmount(), type);
    fee.setText(new Bitcoin(new Satoshi(transactionDto.getFee())).getDisplay());

    if (!"\"\"".equals(transactionDto.getNote())) {
        notes.setText(transactionDto.getNote());
    }

    SimpleDateFormat dateFormat = new SimpleDateFormat("MMMM dd, yyyy, 'at' hh:mma zzz");
    try {
        date.setText(dateFormat.format(transactionDto.getCreatedDate()));
    } catch (ParseException e) {
        e.printStackTrace();
        date.setText(null);
    }

}

From source file:hr.fer.tel.rovkp.homework03.task01.JokesCollection.java

/**
 * Outputs similarity matrix to CSV file
 * in format ID1, ID2, similarity/*  w w w  .ja v a2  s .com*/
 * @param similarityMatrix matrix to print
 * @param file CSV file to create
 * @throws FileNotFoundException 
 */
public static void similarityMatrixAsCsv(float[][] similarityMatrix, String file) throws FileNotFoundException {
    try (PrintWriter out = new PrintWriter(file)) {
        for (int i = 0; i < similarityMatrix.length; i++) {
            for (int j = 0; j <= i; j++) {
                if (similarityMatrix[i][j] != 0) {
                    DecimalFormat format = new DecimalFormat("###.####");
                    out.println((j + 1) + ", " + (i + 1) + ", " + format.format(similarityMatrix[i][j]));
                }
            }
        }
    }
}

From source file:com.imagelake.android.account.Servlet_Account.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    PrintWriter out = response.getWriter();
    try {/*from  www .  ja v  a 2  s  .c o  m*/

        String uid = request.getParameter("uid");

        if (uid != null) {
            User u = udi.getUser(Integer.parseInt(uid));

            if (u != null) {

                if (u.getState() == 1) {
                    JSONObject jo = new JSONObject();//create a JSONObject

                    if (u.getUser_type() != 2 && u.getUser_type() != 3) {
                        double income = 0.0;
                        DecimalFormat df = new DecimalFormat("#.00");
                        try {
                            String sql = "SELECT SUM(total) FROM admin_package_income";
                            PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql);
                            ResultSet rs = ps.executeQuery();
                            while (rs.next()) {
                                income = rs.getDouble(1);
                                jo.put("income", df.format(income));
                            }
                            rs.close();
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                        int usersCount = udi.allUsersCount();
                        jo.put("users", usersCount);

                        int imagesCount = new ImagesDAOImp().getImagesCount();
                        jo.put("imgcount", imagesCount);
                    } else {

                        UserHasPackage uss = uhpdi.getUserActivePackage(u.getUser_id(), 1);

                        //check user package-------------------------------------------
                        if (uss != null) {
                            System.out.println(uss.getExpire_date());
                            System.out.println(date);
                            System.out.println("is expierd:" + uss.getExpire_date().compareTo(date));

                            if (uss.getExpire_date().compareTo(date) <= 0) {
                                boolean okk = new UserHasPackageDAOImp().updateState(uss.getUhp_id());
                            } else {
                                if (!uss.getLast_date().equals(date)) {
                                    if (uss.getPackage_type() == 1) {
                                        //FreeTrial f=new FreeTrialDAOImp().getAFreeTrail(uss.getPackage_type());
                                        UserHasPackage uhpp = new UserHasPackage();
                                        uhpp.setDownload_count(uss.getOrg_downloads());
                                        uhpp.setCredit_count(uss.getCredit_count());
                                        uhpp.setLast_date(date);
                                        uhpp.setUhp_id(uss.getUhp_id());

                                        System.gc();

                                        boolean kk = new UserHasPackageDAOImp().updatePackage(uhpp);
                                        System.out
                                                .println("UPDATE PACKAGE | PACKAGE TYPE IS 1 7 DAY FREE TRIAL");
                                    } else if (uss.getPackage_type() == 2) {

                                        //FreeTrial f=new FreeTrialDAOImp().getAFreeTrail(uss.getPackage_type());
                                        Calendar c = Calendar.getInstance();
                                        c.add(Calendar.DATE, uss.getDuration());

                                        UserHasPackage uhpp = new UserHasPackage();
                                        System.out.println(
                                                "*******************" + uss.getExpire_date().compareTo(date));
                                        if (uss.getExpire_date().compareTo(date) < 0) {

                                            uhpp.setDownload_count(uss.getDownload_count());
                                            uhpp.setCredit_count(uss.getCredit_count());
                                            uhpp.setExpire_date(sdf.format(c.getTime()));
                                            uhpp.setLast_date(date);
                                            uhpp.setUhp_id(uss.getUhp_id());
                                            System.gc();
                                            boolean kk = new UserHasPackageDAOImp().updateExpireDate(uhpp);
                                            System.out.println(
                                                    "UPDATE EXPIRE DATE | PACKAGE TYPE IS 2 MONTH FREE TRIAL");

                                        } else {

                                            uhpp.setDownload_count(uss.getDownload_count());
                                            uhpp.setCredit_count(uss.getCredit_count());
                                            uhpp.setExpire_date(sdf.format(c.getTime()));
                                            uhpp.setLast_date(date);
                                            uhpp.setUhp_id(uss.getUhp_id());

                                            System.gc();
                                            boolean kk = new UserHasPackageDAOImp().updatePackage(uhpp);
                                            System.out.println(
                                                    "UPDATE JUST LAST DATE | PACKAGE TYPE IS 2 MONTH FREE TRIAL");
                                        }
                                    } else if (uss.getPackage_type() == 3) {
                                        SubscriptionPackage sp = new SubscriptionPackageDAOImp()
                                                .getSubscription(uss.getPackage_id());
                                        if (sp.getSubscription_type_id() != 2) {
                                            //DownloadCount dc=new DownloadCountDAOImp().getCount(sp.getCount_id());
                                            UserHasPackage uhpp = new UserHasPackage();
                                            uhpp.setDownload_count(uss.getOrg_downloads());
                                            uhpp.setCredit_count(uss.getCredit_count());
                                            uhpp.setLast_date(date);
                                            uhpp.setUhp_id(uss.getUhp_id());

                                            System.gc();

                                            boolean kk = new UserHasPackageDAOImp().updatePackage(uhpp);
                                            System.out.println(
                                                    "UPDATE PACKAGE | PACKAGE TYPE IS 3 SUBSCRIPTION PACKAGE");
                                        }
                                    }
                                }
                            }
                        } //

                        UserHasPackage up = uhpdi.getUserPackage(u.getUser_id(), 1, 3);

                        if (up == null) {

                            jo.put("subscription", "Image Subscription");
                            jo.put("ps1", "You have no active image subscriptions");
                            jo.put("issNull", "yes");

                        } else {

                            SubscriptionPackage sp = spdi.getSubscription(up.getPackage_id());
                            String type = spdi.getSubscriptionType(sp.getSubscription_type_id());
                            String title = uhpdi.getPackageType(up.getPackage_type());
                            DownloadCount dc = dcdi.getCount(sp.getCount_id());
                            int dowPerDay = dc.getCount();

                            jo.put("subscription", "" + dowPerDay + " images " + type + " " + title + " for "
                                    + sp.getDuration() + " Month");
                            jo.put("ps1", "Purchase Date : " + up.getPurchase_date());
                            jo.put("ps2", "Expire Date : " + up.getExpire_date());
                            jo.put("ps3", "you have left " + up.getDownload_count() + " downloads for today");
                            jo.put("issNull", "no");

                        }

                        UserHasPackage p = uhpdi.getUserPackage(u.getUser_id(), 1, 4);

                        if (p == null) {

                            jo.put("credits", "Image Credit Packs");
                            jo.put("pc1", "You have no active credit packs");
                            jo.put("iscNull", "yes");
                            //   jo.put("pckType","2");

                        } else {
                            SubscriptionPackage sp = spdi.getSubscription(p.getPackage_id());
                            String title = uhpdi.getPackageType(p.getPackage_type());

                            jo.put("credits", p.getCredit_count() + " " + title + " Package");
                            jo.put("pc1", "Purchase Date : " + p.getPurchase_date());
                            jo.put("pc2", "Expire Date : " + p.getExpire_date());
                            jo.put("pc3", "you have left " + p.getCredit_count() + " credits for today");
                            jo.put("iscNull", "no");
                            //  jo.put("pckType","2");

                        }

                    }
                    out.write("json=" + jo.toJSONString());
                    System.out.println("json" + jo.toJSONString());
                } else {
                    out.write("msg=Blocked by the admin");
                }

            } else {
                out.write("msg=Internal server error,Please try again later.");
            }

        } else {

            out.write("msg=Internal server error,Please try again later.");
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:fr.bde_eseo.eseomega.events.tickets.model.EventTicketItem.java

public String getTicketNumberAsString() {
    return strcmd + new DecimalFormat("000").format(modcmd);
}