[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Formating float output in a gui textfield

Posted on 2007-04-05
6
Medium Priority
?
230 Views
Last Modified: 2010-03-31
Hi Experts,
Just a quick one. I have a banking system that i am programming for an assignment, output is via a GUI, i have everything working ut am not happy with the output of float values, i am outputing in 4 dp when i only want 2 dp. Can you help, 200 points fo a quick answear the relevant code is below

private void displayAccountDetails()
        {
            currentSelectedCustomer = branch.getCustomerAt(customerComboBox.getSelectedIndex());
            balanceTextField.setText("");
          limitTextField.setText("");
            interestTextField.setText("");
          //depending on the account type....
          if(accountTypeComboBox.getSelectedIndex() == 0)
            {
               
              CreditCardAccount acc = currentSelectedCustomer.getCreditCardAccount();
            accountNumberTextField.setText(acc.getAccNumber());
            balanceTextField.setText(""+acc.getBalance());
            limitTextField.setText("Limit: " + acc.getLimit());
                interestTextField.setText("Rate: " + acc.getCreditCardRate());
          }
          else
              if(accountTypeComboBox.getSelectedIndex() == 1)
                {
                CurrentAccount acc = currentSelectedCustomer.getCurrentAccount();
                accountNumberTextField.setText(acc.getAccNumber());
                balanceTextField.setText(""+acc.getBalance());
                limitTextField.setText("Limit: " + acc.getLimit());
            }
          else
              if(accountTypeComboBox.getSelectedIndex() == 2)
                {
                SavingsAccount acc = currentSelectedCustomer.getSavingsAccount();
                accountNumberTextField.setText(acc.getAccNumber());
                balanceTextField.setText(""+acc.getBalance());
                interestTextField.setText("Rate: " + acc.getSavingsRate());
            }
      }

and the source for the balance

 //get account details
    public float getBalance() //selector method
    {
        return accBalance;
    }

Thanks in advance
0
Comment
Question by:manuman1968
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 30

Expert Comment

by:Mayank S
ID: 18861374
>> Formating float output

Define the field as a double, not a float.

http://www.exampledepot.com/egs/java.text/FormatNum.html
0
 

Author Comment

by:manuman1968
ID: 18861633
Sorry but thats completely lost me as a newcomer, any chance of showing me an example of code.
Thanks
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 5

Accepted Solution

by:
tbboyett earned 2000 total points
ID: 18861644
It would be something like this.  You can set the DecimalFormat to what ever you want the number to look like.

DecimalFormat df = new DecimalFormat("###.00");
double mynumber = 245.4444;
TextField.setText(df.format(mynumber));
0
 
LVL 5

Expert Comment

by:tbboyett
ID: 18861647
don't forget to do the import, i believe it's java.text.

import java.text.*;
0
 

Author Comment

by:manuman1968
ID: 18861701
Thanks that works
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question