Formatting a float in Java, help please!

Im trying to format a float in a JTable thats been taken from an SQL database, heres what ive got:
float price = results.getFloat(5);
row = new Vector();
row.addElement(new String(results.getString(1)));
row.addElement(results.getString(2));
row.addElement(results.getInt(3));
row.addElement(results.getInt(4));
row.addElement("�"+ (price));
rows.addElement(row);
so i've given the getFloat(5) a variable name 'price' - how do i format the float 'price' to two decimal places, like 0.00? is it some thing like:
float price.%2f = results.getFloat(5);
I cant remember, thanks!

yeh i tried to implement it, but no joy, the JTable still displays to 1 decimal place, which is very odd...
the JTable displays as strings, but its retrieving a float (results.getFloat(5)) so i thought if i called the results.getFloat as a string, then used:
Float price = Float.valueOf(results.getFloat(5)).floatValue();
String.format("%.2f", price);
it would work... i was wrong, lol

Similar Messages

  • WebVPN floating toolbar customization help please?

    My webvpn portal page has below floating toolbar displayed either on top-left or top-right corner.
    Q1 - Is there a way to position the toolbar on top-middle of the pager?
    Q2 - Is there a way to per-defined the position of the toolbar when portal page is loaded?
    Reason being is that the toolbar is displayed on top of some dropdown menus & http links which users have difficulty accessed to it.  I would like to move this toolbar to the top-middle of the page, if possible.
    Thanks in advance for your help and assistance.
    Joe

    Thanks Karthik for taking time to look at this, i appreciated.
    I looked at the link you sent and understand that i may able to add something like <p align="center"> to make the flooting toolbar showing up on top-middle of the page.  Actually, I exported the exisitng xml file from ASA and tried editing the codes but with no luck.
    Problem is that I am not good at xml file, i am having a hard time to locate the floating toolbar command-line syntax in the xml file.  Can somone please help?  I have attached the existing xml file as an attachment for reference.
    Your help is greatly appreciated.  Thanks
    Joe

  • Mysql syntax in java help please!!

    the below code works nice, but how do i place a variable in the VALUES part of the recordsUpdated statement. I can only place in numbers or letters but not variables. Lets say i want to loop this 20 times and i want it to write to the table 20 times, each time, the number int the VALUES increments (p++) where p is the variable. How do i place the varible in the sql statement? is that possible? or is there even a way?
    for(p = 100; p<120; p++)
    recordsUpdated = stmt.executeUpdate("INSERT INTO users (userid, usernum) VALUES(344, 452)");
      rs = stmt.executeQuery("SELECT userid, usernum FROM users");
          }thanks for any help!! =)

    Try
    String sql="INSERT INTO users (userid, usernum) VALUES(?, ?)";
    PreparedStatement pmt = databaseConnection.prepareStatement(sql);
    for(int i = 0; i < 20; i++) {
              pmt.setInt(1, firstVar);
              pmt.setString(2, secondVar);
              pmt.executeUpdate();
    See at Java API for more information about prepared statements.

  • Using command prompt through java, help please!

    Hi,
    What I am trying to do is find all the processes running onthe computer using java. Normally, I would do this (without java) by opening a command prompt window, typing in tasklist and see all the running processes. I have tried to to do the same thing using java, but so far have been unsucsessful. Here is my code:
    import java.io.*;
    public class Main {
            static DataOutputStream output;
            static DataInputStream input;
            static String app="cmd.exe";
            static String command="tasklist";
            static String message="";
            public static void main(String args[])throws Exception{
            Process process = Runtime.getRuntime().exec(app);
            output=new DataOutputStream(process.getOutputStream());
            input=new DataInputStream(process.getInputStream());
            output.write(command.getBytes());
            byte[] b=new byte[input.available()];
            input.readFully(b);
            message=new String(b);
            System.out.println("Message: "+message);
            System.out.println(!message.equals(""));
            System.out.println(message!=null);
            System.out.println("Finished Program");
    }And this program prints the output (with no exceptions):
    Message:
    false
    true
    Finished Program
    I appreciate any help in fixing my program...

    DevRocks_Java wrote:
    static String app="cmd.exe";
    static String command="tasklist";
    Process process = Runtime.getRuntime().exec(app);
    output=new DataOutputStream(process.getOutputStream());
    input=new DataInputStream(process.getInputStream());What do you expect it to do? You are only telling it to open a console window, nothing more.
    if you can type tasklist at the run option, then you should be able to just substitute command in for app in your exec.

  • JAVA HELP: Please take a look****

    I'm creating a program compute the arrival time of a train, if you know the starting time and the distance to destination (in km). Assume that the average speed of the train is 60km/h. The start time is given as the hour (using 24h notation) and the minutes. For example, if the start time is 13:46, the user will input 13 and 46. Assume that the hour and minutes provided are valid values. The output will consist in two numbers, one for the hours and one for the minutes.
    Example: if the train travels 210 km, and the start time is 10:20, then the arrival time will be 13:50 (actually two numbers representing 13h and 50min).
    class average{
      public static void main(String args[]){
         we will bb taking three values from user and
         calculate the sum and average of inputs
        // declare the variable
        double distance;
        double distancehour;
        double distanceminute;
        double avgspeed= 60/60; // average speed of the train
        double time; // average of teh three values
        // promt user to enter the values
        System.out.println("Please input the distance your are travelling:");
        distance = ITI1120.readDouble();
            while (distance < 0) {
        System.out.println("Please input the hour of departure (in 24 Hour format):");
        distancehour = ITI1120.readDouble() ;
            while (h <0) // \\ (h >=24)) {
        System.out.println("Please input the minute(s) of departure (in 24 format):");
        distanceminute = ITI1120.readDouble();
            // Intermediate
        double startminutes = distancehour*60+distanceminute; //convert hour into minutes
        double converttime = distance*avgspeed; // distance of travel multiplied by avg speed
        double subtotalminutes = startminutes+converttime;
        double totalhours = subtotalminutes/60;
        double totalmins = totalhours*60;
        double totalminutes = subtotalminutes+totalmins;
          // Result
        System.out.println("Your travel time is: " +totalhours : +totalminutes);
      }What am I doing wrong? The code isn't functioning completely.

    hi,
    try this if i got right,this program will give u the desired o/p.
    i think this will give u satisfaction,if i m right then rply me,
    public static void main(String args[])
    double distance=0;
    double distancehour=0;
    double distanceminute=0;
    double avgspeed= 60/60; // average speed of the train
    double time; // average of teh three values
    System.out.println("Please input the distance your are travelling:");
    distance = 90;
    if(distance > 0) {
    System.out.println("Please input the hour of departure (in 24 Hour format):");
    distancehour = 12 ;
    if (distancehour >0) // (h >=24)) {
    System.out.println("Please input the minute(s) of departure (in 24 format):");
    distanceminute = 34;
    // Intermediate
    double startminutes = distancehour*60+distanceminute; //convert hour into minutes
    int hourcolp=(int) distance/60;
    double mincolp= distance%60;
    //double converttime = distance*avgspeed; // distance of travel multiplied by avg speed
    //double subtotalminutes = startminutes+converttime;
    //double totalhours = subtotalminutes/60;
    //double totalmins = totalhours*60;
    //double totalminutes = subtotalminutes+totalmins;
    // Result
    //double totalminutes = subtotalminutes+totalmins;
    int totalhours = (int)distancehour+hourcolp;
    int totalmins = (int)distanceminute+(int)mincolp;
    totalhours= totalhours+(int)totalmins/60;
    totalmins= totalmins%60;
    System.out.println("Your travel time is: " totalhours ":" +totalmins);
    }

  • Run diffierent movie formats in Flash Player. Help Please

    Hi,
    I want to run different movie formats upload by user in
    Flash Player. Something like U Tube functionality
    1 - Is there any player that run different movie formats like
    MP3, AVI etc directly into Flash Player. No need to convert?
    Another way is to convert different formats into FLV and
    than run into flash player.
    Is there any good FLV converter out there which converts on
    the web during user upload.
    Or user upload movie that is than converted to FLV but part
    of web application not desktop application.
    Any code or any tutorial to covert into FLV?
    Platform is windows server 2003 and application is ASP.NET
    2.0
    Thanks

    Spotlight search "Flash Player.plugin" and search the entire Mac HD.
    Trash EVERYTHING that appears (there should be between 8 and 12 items depending on what you have installed)
    Empty the trash
    Reset Safari per Apple instructions
    Then follow the instructions here:  How to perform a "clean install" of Flash Player in Mac OS X

  • Errors loading ".so" into java - Help please

    I am having problems accessing .so from java . I have a libgpda.so that contains mostly rmi stuff. I loaded this library using System.loadLibrary("gpda") and also added the path to the LI_LIBRARY_PATH as well as LD_LIBRARYN32_PATH . I am running this on irix.
    when I run this application, I get an error that says
    "java.lang.rmierror: Error occurred in server thread. nested exception is:
    unsatisfied link error: /home/vjilledi/libs/ligpda.so
    cannot successfully map soname '/home/vjilledi/libs/ligpda.so' under any of the file name /home/vjilledi/libs/ligpda.so.
    Some observations that I made:
    1. In the code, I don't get this error while I do a loadLibrary(). I get this error while I make the first call to the stuff declared in the .so.
    2. If I remove libgpda.so from '/home/vjilledi/libs/' , I get an error that says that 'couldn't find libgpda.so in java.lang.path ... which I understand .
    I am running java1.3 . or irix6.5

    1. Post the definition of your native method, and also the class and native method declarations.
    2. Did you notice the apparent misspelling between you library name and the native method in the error message?

  • How to insert a default value into MS server in java - help please

    hi
    suppose if i have a table and one of the column has a default value when the table was created. how can i insert the default value into this column? assuming that the column is the second column and i can't specify the column name when inserting. thanks.

    thanks for ur response, so if i have insert statement as follow
    insert into someTable values (1,'val1', 'val2', 'val3', 'val4')
    and column 3 has default value = DEFAULT
    then, to insert default value, my insert statement will look like this
    insert into someTable values (1,'val1', 'val3', 'val4')
    but the number of values will not match the number of columns.

  • After upgrading to Yosemite I cannot share my pages document by mail as a word format - HELP please!!!

    After upgrading to Yosemite I cannot share my pages document by mail as a word format - HELP please!!!

    You don't need to go to the App Store to for support for Steam and Minecraft. You need to go to their website(s).
    You're welcome 

  • I was always instructed by Apple to install all updates.  I followed their advice and my Java disappeared and I can no longer play pogo scrabble.  pogo's "advice" to install Java is useless.  HELP PLEASE!

    I was always instructed by Apple to install all new updates offered.  When I installed the last one on my 10.5.7 macbook, my java disappeared.  Java's advice is useless.  I can no longer play pogo scrabble without java.  Please help.  Thank you very much.

    MadMAC0 posted at https://discussions.apple.com/message/20107182?ac_cid=tw123456#20107182 that:
    Apple has posted (10/22/12) the approved solution for restoring the Java 6 plug-in:
    Java for OS X 2012-006: How to re-enable the Apple-provided Java SE 6 applet plug-in and Web Start functionality.

  • Please help i started my project video format 720HD resolution 12x720 rate 25p at last when i finish and burn to dvd the edges are cut off any one help please i am really in trouble

    please help i started my project with  video format 720HD, resolution 12x720, rate 25p.  at last when i finish and burn to dvd the edges are cut off and my logo cut off the screeen aswell any one help please i am really in trouble. thanks

    Sorry, but I don't know anything about that app.
    I did go to their Web site and I see they have a support link. Perhaps you can get help there or in their forum.
    If you are OK with a DVD with a basic menu, you could try the Share>DVD option in FCP.
    Good luck.
    Russ

  • Why can't I download from kuler, my computer doesn't recognise the .ase files its says its an unknown format, can anyone help please.  Thanks?

    why can't I download from kuler, my computer doesn't recognise the .ase files its says its an unknown format, can anyone help please?

    why can't I download from kuler, my computer doesn't recognise the .ase files its says its an unknown format, can anyone help please?

  • Java mapping help please

    Hi all,
    I need help with java code please.
    My source is a csv file and target is multiple idocs.
    Source file structure is as follows:
    Header (field 1, field 2, ........ field 10)
    Item 1a (field 1, field 2, field 3, .........    field 180)
    Item 1b (field 1, field 2, field 3, .........    field 180)
    Item 2a (field 1, field 2, field 3, .........    field 180)
    Item 2b (field 1, field 2, field 3, .........    field 180)
    Item na (field 1, field 2, field 3, .........    field 180)
    Item nb (field 1, field 2, field 3, .........    field 180)
    First line is header. Second is VAT line. Third is Price line for that VAT. Now VAT and Price lines repeat. There need not be VAT line for non-European countries. So a VAT line may or may not preceed a Price line.
    For example: the lines can be like:
    Header
    VAT1
    Price1
    VAT2
    Price2
    Price3
    1) Now, it should produce 3 idocs like:
    Header, VAT1, Price1
    Header, VAT2, Price2
    Header, Price3
    2) One idoc should be created per a pair of VAT and Price lines and they will be identified by a co-relation of a particular field. So first I have to sort all the lines based on this field value. Then I have to read the lines in pairs. If no Vat line, I should just read the Price item and produce an idoc.
    Can you please help me with the java code for this?
    Many thanks in advance.
    Ramesh.

    Many thanks Ram.
    The reason for thinking to go for java mapping is that there is no keyfield for price line. The source file is a pipe delimited csv file. There is a keyfield for VAT line. The same field will be empty for the Price line. I am trying to ask them to at least provide a space for that field between the pipes for price line so that I can use in FCC. It looks like they can't modify the source file.
    Any inputs please?
    Regards.
    Ramesh.

  • I can't open ibooks. There was a screen pop up about java se. Help please.

    I can't open ibooks. There was a screen pop up about java se. Help please.

    Hi there ajsupprt,
    It sounds like you may need to update the version of Java installed on your computer. Take a look at the article below for more information.
    Java updates available for OS X on August 28, 2013
    http://support.apple.com/kb/ht5648
    -Griff W.

  • Displaying Picture in a Java APPLICATION please help!!

    I have been trying to write a method that Displays a .jpg file when called. However I have not gotten far, every book I have tell you how to display pictures in an applet but not an application. I did find some code that is supposed to be for an application, but It does not compile right. Any help would be apprecidated!
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class PictureIt{
    public void makeImage() {
    //***Image Output Stream
    String imgFile
    = "d:\\temp\\TestImage.jpeg";
    out = new FileOutputStream(imgFile);
    BufferedImage image = null;
    image = (BufferedImage)createImage
    (panelJpeg.size.width, panelJpeg.size.height);
    Graphics g = image.getGraphics();
    panelJpeg.paintAll(g);
    }

    Displaying Picture in a Java APPLICATION please help!!
    Hope this helps.There is going to be two classes compile seperatly first class is what does the drawing
    here it is
    import javax.swing.*;
    import java.awt.*;
    public class draww extends JPanel {
    Image ball;
    int width1 = 100;
    int height1 = 100;
    public draww() {
    super();
    Toolkit kit = Toolkit.getDefaultToolkit();
    ball = kit.getImage("pic1.gif");
    public void paintComponent(Graphics comp) {
    Graphics2D comp2D = (Graphics2D) comp;
    comp2D.drawImage(ball, 20, 20, width1, height1, this);
    sound class is the container JFrame here it is
    import javax.swing.*;
    import java.awt.*;
    public class drawing extends JFrame {
    public drawing() {
    super("draw");
    setSize(400,400);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container pane = getContentPane();
    draww d = new draww();
    pane.add(d);
    setContentPane(pane);
    setVisible(true);
    public static void main(String[] args) {
    drawing drawing1 = new drawing();
    PS Hope this helps and see you around

Maybe you are looking for

  • A110 memory modules

    TOSHIBA EQUIUM A110 PSAB2E-008006AV. I have just replaced two memory modules both 516 mb with a 2gb module. Everything works fine. However, I have heard varying comments about maximum memory; I have been told that the maximum is 2gb, but I have heard

  • Use of Serial Numbers in Deliveries and Goods Issue

    Hi, We are using externally created serial numbers in Sales deliveries. At the time of creation of Serial Number we are maintaining Plant code in Stock Data and creating an Equipment for every serial number. Now at the time of Delivery when user assi

  • OBI Publisher 11.1.1.5 install questions

    Hello, I am new to OBI Publisher. I need OBIP for production PDF reports that are initiated through an APEX webpage. I am installing all of these on the same server: 11.2.0.2 database Oracle HTTP Server (OHS) OBI Publisher I am having trouble install

  • Flash Video in DW too slow

    I am trying to build a page at http://lotus.org/docs/video3.htm. I've got two problems: 1. The page loads very slowly on a high-speed connection and really clogs the RAM on dialup. It is not usable as is. I created the page using Insert/Media/Flash V

  • HT202998 copy paste in windows browsers numbers beta not working?

    Hi, Whenever I try to copy/paste an XLS file in numbers icloud, the file gets really messy. Data gets allocated to different cells compared to the original file. I have been using both Google Chrome and Firefox for windows, but have had no luck. Any