Result to two decimal places

Hi I have the following code for currency conversion, now I want that when a converted currency result is for example 1.8 it displays 1.80 ie to two decimal places. how is this done? thanks
private void converteurosButtonActionPerformed(java.awt.event.ActionEvent evt) {                                                  
//Parse Euros as a double and convert to GBP.
    DecimalFormat df = new DecimalFormat("#,###.##");
    double gbp = (double) (Double.parseDouble(eurosTextField1.getText())) * 0.796345;       
    convertedeurosLabel.setText("� "+df.format(gbp));

  private static DecimalFormat format = new DecimalFormat("0.00");
  private String format(double value) {
    return format.format(value);
// call  as
format(2.999);

Similar Messages

  • Displaying results with a decimal place of two. Forcing decimal place.

    Hi there,
    Im writing a simple calculation device.
    You input one digit and press one of two buttons to multiply it by a certain number and then the result is displayed. The result is displyed hiding the result of the button you didn't press and visa versa.
    I am having a problem displaying the result with a constant two decimal place.
    I am using strings and thus don't know how to do this.
    Here is my code:
    import flash.events.MouseEvent;
    //restrict the input textfield to only numbers
    txtinput.restrict = "0-9";
    //restrict the input textfield to only two characters
    txtinput.maxChars = 6;
    // event listeners
    btnW.addEventListener(MouseEvent.CLICK, WHandler);
    btnC.addEventListener(MouseEvent.CLICK, CHandler);
    btnW.addEventListener(MouseEvent.CLICK, hideC);
    btnC.addEventListener(MouseEvent.CLICK, hideW);
    //functions
    function WHandler (e:MouseEvent):void
              //white calculation
              var answerW:Number = Number(txtinput.text) * Number(0.90);
              txtWResult.text = answerW.toString();
    function CHandler (e:MouseEvent):void
              //colour calculation
              var answerC:Number = Number(txtinput.text) * Number(0.99);
              txtCResult.text = answerC.toString();
    function hideC (e:MouseEvent):void
              //Hide colour result
              txtCResult.visible = false;
              txtWResult.visible = true;
    function hideW (e:MouseEvent):void
              //Hide white result
              txtWResult.visible = false;
              txtCResult.visible = true;
    After having a look online I have found these two resources:
    http://helpx.adobe.com/flash/kb/rounding-specific-decimal-places-flash.html
    and
    http://stackoverflow.com/questions/11469321/decimals-to-one-decimal-place-in-as3
    But I am confused when combining these techniques with strings.
    Any help would be greatly appreciated,
    Thanks in advance
    Mr B

    Use the toFixed() method of the Number class instead of the toString() method.  The result of it is a String with the number of decimal places you specify.
              var answerW:Number = Number(txtinput.text) * Number(0.90);
              txtWResult.text = answerW.toFixed(2);
              var answerC:Number = Number(txtinput.text) * Number(0.99);
              txtCResult.text = answerC.toFixed(2);

  • Convert amount with four decimal places to amount with two decimal places

    Hi,
    for specific reasons we have set the prices to four decimal places. However, in an invoice the staff needs to see all prices with two decimal places. Therefore I have created new user-defined fields which should show the rounded values However, I have not yet found the right formatted search that outputs the value with two decimal places including currency symbol.
    The statement 
    SELECT $[$38.20.NUMBER]
    outputs the value with two decimal places which is fine, but it does not contain the currency.
    The statement
    SELECT $[$38.20.0]
    outputs both value and currency, but the value still has four decimal places as the original price.
    And the statement
    SELECT CAST($[$38.20.NUMBER] AS VARCHAR(20)) + $[$38.20.CURRENCY]
    outputs a value with even six decimal places.
    Did anyone already have the same problem???
    Or does anyone have any idea???
    Thanks and regards
    Corinna

    Hi again,
    the value should be displayed in a user-defined field of the screen.
    The result of the query
    SELECT $[$38.20.NUMBER]
    has already two decimal places, so that I do not need a round here. But the currency is missing.
    When I add the round function to the query
    SELECT $[$38.20.0]
    it does unfortunatly result in an error.
    Any ideas????
    Thanks so much in advance!

  • How do I round calculations to two decimal places (form-wide)

    Hi,
    I've created an order form where customers input the quantity of product they want to order and the form outputs the total due (including shipping and sales tax). Depending on user input, the resulting total sometimes contains more than two decimal places. How do I round calculations to two decimal places? Is there a way to do this form-wide?
    I'm new at using Acrobat for calculations. Any help would be greatly appreciated! Thanks...

    The above will affect the displayed value not the actual value of the field nor its value when accessed in another computation. This behavior may cause an error of 1 cent or more in the grand total or sales tax computation. If you want the the value and displayed value to be the same value you can use the following Validation script:
    event.value = util.scand("%,1 0.2f", event.value);

  • Limiting AS distance to two decimal places

    I am just about there getting the Google Maps API talking to my SQL database. For my search results I have the SQL:
    SELECT *, ( 3959 * acos( cos( radians(" .$POST["latitude"] .") ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(" .$POST["longitude"] .") ) + sin( radians(" .$_POST["latitude"] .") ) * sin( radians( lat ) ) ) ) AS distance FROM VenuesGeocodes1 HAVING distance < 100 ORDER BY distance LIMIT 0 , 30;
    Which works great, but displays the distance with 15 decimal places which is complete overkill.
    How can I limit that to just two decimal places? I thought I just needed to change distance to distance (10,2), but it didn't like it.
    If anyone can let me know what it should be that would be much appreciated.
    Thanks.

    Thanks Rob - I also got it to work using ROUND in the query:
    SELECT *, ROUND( 3959 * acos....

  • Rounding off to two decimal places

    Hello,
    For simplicity, is there a method which will round off
    a double variable to two decimal places.
    Excample: if I have a result which equals 2.1999998
    and I want to display this as 2.20 in a TexTField.
    Any help would be much appreciated.
    Thanks

    If you are trying to do dollars and cents, I further recommend you use:NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance();
    String currencyOut = currencyFormatter.format(yourNumber);to format your numbers as they will give the correct precision for international currencies simply by setting the locale, and they will also automatically handle the currency symbols ($, DM FR, etc.)
    Doug

  • Printing to two decimal places on the screen

    Hi everyone...
    I am using mysql as my DB...my field is declared there as decimal(8,2) means to 2 decimal place..when i am getting the result i also need to print to 2 decimal place...
    so when i do(rs.getDouble("Price")) it is not printing as two decimal place...how do i get it to print to 2 decimal place...
    Thanx a lotttttt

    javax.text.DecimalFormat dfrm t=new java.text.DecimalFormat("#0.00");
    //or another format see API doc for DecimalFOrmat
    String result = dfrm.format(rs.getDouble("Price"));

  • Convert to two decimal places

    Hi I have some code which I have written but am unable to convert it to two decimal places. Have tried various techniques by looking through some of the forums. My problem is that my data starts off as varchar(500) and initially I have to substring to get
    the actual numeric part of the data.
    At the moment i get a result such as 48487.800000. I would like 48487.80.
    Just wondering if anyone has any ideas where I could be going wrong. Here is my effort.
    select SUM(Next_Value)/100 AS ResultExpected from
    Select A.ID,  A.LogData,
          (Select Top 1 
    --CONVERT(numeric,
         -- cast(substring(B.LogData,6,36) AS numeric(10,2))
          --CONVERT(numeric(8,2),cast(substring(B.LogData,6,36) as numeric(8,2)) )
           cast(substring(B.LogData,6,36) as numeric(10,2))
          From HMRC_Load B
             Where B.Id > A.Id and A.LogData like 'NewFigure%'
             order By B.Id) as Next_Value 
    From HMRC_Load A
    where A.LogData like 'NewFigure' 
    ) AS ResultExpected
    Top Geezer

    select CAST(SUM(Next_Value)/100 AS Numeric(10,2)) AS ResultExpected from
    Select A.ID, A.LogData,
    cast((Select Top 1
    substring(B.LogData,6,36)
    From HMRC_Load B
    Where B.Id > A.Id and A.LogData like 'NewFigure%'
    order By B.Id) as numeric(10,2)) as Next_Value
    From HMRC_Load A
    where A.LogData like 'NewFigure'
    ) AS ResultExpected
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Two decimal places

    Hello, i want to have my results in my shop apllication in two decimal places. I tried DecimalFormat f = new DecimalFormat("#.##"); with import java.text.DecimalFormat; but it doesnt change the decimal places.
    And when i try this class example which i found on http://www.roseindia.net/java/beginners/RoundTwoDecimalPlaces.shtml it says that inner classes cannot have static declarations on public static void main(String[] args) {          and     public static float Round(float Rval, int Rpl) {
    Im using netbeans 5,5, does someone know what the problem is?
    public class RoundTwoDecimalPlaces{
    public static void main(String[] args) {
    float num = 2.954165f;
    float round = Round(num,2);
    System.out.println("Rounded data: " + round);
    public static float Round(float Rval, int Rpl) {
    float p = (float)Math.pow(10,Rpl);
    Rval = Rval * p;
    float tmp = Math.round(Rval);
    return (float)tmp/p;
    Edited by: javaboy on Nov 11, 2007 12:46 PM

    package view;
    import java.awt.Color;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.ArrayList;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import controller.index;
    import model.product;
    import java.text.*;
    public class View_basket extends JPanel implements ActionListener{
         private static final long serialVersionUID = 1L;
         private index index;
         private JButton btnGoToPay;
         private JLabel[] lblProducts, lblPrices;
         private int countProducts;
         private int offset=40;          // # of pixels from the top
         private int increment=20;     // the next product will appear this amount of pixels below it's predecessor
         private JPanel container;
         public View_basket(index index){
              this.container = new JPanel(null);
              this.container.setName("Shopping basket");
              this.container.setBackground(new Color(151, 186, 225));          
              this.container.setSize(190,200);
              this.container.setLocation(550,20);
              this.index=index;
         public JPanel updateGui(){
              System.out.println("class view.View_basket.updateGui()");
              ArrayList products = index.basket.getProducts();
              countProducts = products.size();
              // if product basket is to big, resize the basket frame
              if(countProducts > 6){
                   this.container.setSize(190,(300+((countProducts-6)*10)));     
              lblProducts = new JLabel[countProducts];
              lblPrices = new JLabel[countProducts];
              JLabel lblTitle = new JLabel();
              lblTitle.setText("Winkelmand");
              lblTitle.setBounds(5, 5, 150, 20);
              lblTitle.setFont(index.FONT_12_BOLD);
              this.container.add(lblTitle);
              int teller=offset;
              double total=0;
              // walk trough all values from the arrayList
              for(int i=0; i < countProducts; i++){
                   product product = (product)products.get(i);
                   lblProducts[i] = new JLabel(product.toString());
                   lblProducts.setBounds(5, teller, 130, 20);
                   lblProducts[i].setFont(index.FONT_10_PLAIN);
                   this.container.add(lblProducts[i]);
                   lblPrices[i] = new JLabel("? "+ product.getPrice());
                   lblPrices[i].setBounds(140, teller, 150, 20);
                   lblPrices[i].setFont(index.FONT_10_PLAIN);
                   this.container.add(lblPrices[i]);
                   teller +=increment;
                   total += product.getPrice();
              // create total labels
              JLabel lblTotal = new JLabel("Totaal: ");
              lblTotal.setBounds(5, teller, 50, 20);
              lblTotal.setFont(index.FONT_10_BOLD);
              this.container.add(lblTotal);
              // create total labelseeuro
              JLabel lblTotalPriceeuro = new JLabel("? "+ total);
              lblTotalPriceeuro.setBounds(140, teller, 50, 20);
              lblTotalPriceeuro.setFont(index.FONT_10_BOLD);
              this.container.add(lblTotalPriceeuro);
    // create total labelsdollar
              JLabel lblTotalPricedollar = new JLabel("$ "+ total*1.45);
              lblTotalPricedollar.setBounds(140, teller, 50, 40);
              lblTotalPricedollar.setFont(index.FONT_10_BOLD);
              this.container.add(lblTotalPricedollar);
              int btnOffset = this.container.getHeight()-25;
              btnGoToPay = new JButton("Betalen...");
              btnGoToPay.setBounds(5, btnOffset, 180, 20);
              btnGoToPay.setFont(index.FONT_12_BOLD);
              btnGoToPay.addActionListener( this );     
              if(countProducts == 0)
                   btnGoToPay.setEnabled(false);
              this.container.add(btnGoToPay);
              return container;
         public void actionPerformed(ActionEvent event) {
              // if the pay button is pressed
              if(event.getSource().equals(btnGoToPay)){
                   ((View_pay) index.panelPay).updateGui();
                   index.showPanel("View_pay");

  • Trunc percentage two decimal places

    I have a report that has the option of dispalying pdf or excel. I have the pdf version working fine but i am having a little trouble on the excel version. I have a grand total and department total. Basically I need help formating two decimal places. Both dept_total and grand_total are numbers that both display. I have another column that displays what percent of the total is from each dept.It currently returns a number such as 10.23383547957459973 which i need to display as 10.23 How can i incorporate the trunc function into this code?
    ...to_char((dept_total/grand_total) *100)
    The query looks similar to this.
    select
    to_char(a._grand_total)
    ,to_char(a.dept_total)
    ,to_char((dept_total/grand_total) *100)
    from(
    select sum(xxxx) grand_total,
    sum(xxxx) dept_total
    from table)a

    Hi,
    Since you're calling TO_CHAR anyway, you can add a 2nd argument, specifying two decimal places:
    select
         a._grand_total
    ,     a.dept_total
    ,     to_char ((dept_total/grand_total) *100,       '999999999.99')     AS pct
    from     (
             select  sum (xxxx) grand_total,
                      sum (xxxx) dept_total     -- Why have two copies of the same value?
             from    table
         )a If you're not using a 2nd argument, why use TO_CHAR at all in this query?
    This will round the value, not truncate it. That is, if the value is 10.23<b>5</b>83547957459973, it would display '10.2<b>4</b>', not '10.2<b>3</b>'. If you always want to round toward 0 (rather than to the nearest multiple of .01), then use TRUNC.

  • How to set  two decimal places in currency inr

    hi,
    i want to set two decimal places for my co.code currencu inr.  In t-code oy04 there is no 2 decimal places. Please tell me how set decimal places so that amount in account balances should be in two decimal places.
    thanks
    amol

    Hello,
    If your currency code entry isn't in OY04 customizing step, your currency code has 2 decimal place automaticly. If you want to define a special decimal place without "2", you must define it in OY04.
    Regards,
    Burak

  • Rounding to two decimal places in BPC/NW

    Hello,
    I am dealing with the task to round values to two decimal places. I have found some discussions in BPC-MS where the statement ROUND should work in logic. Unfortunately I am not able to make it work in the NW version.
    Isn't there also a parameter in the appset or application administration which would cut the numbers only to two decimal places (this task would be also a possible solution for us).
    Thanks for any help
    Jan

    Hello Pravin,
    the second import worked fine. I realized that the class has changed to ZCL_BPC_SL_ROUND.
    I debugged the class and noticed that the parameter it_cv is not filled at all. Therefore the program ends before starting the rounding procedure. Here is the part of the code:
    Take CV into account
      clear l_success.
      loop at it_cv into ls_cv.
        clear l_val_string.
        loop at ls_cv-member into l_member.
          if sy-tabix eq 1.
            l_val_string = l_member.
          else.
            concatenate l_val_string l_member into l_val_string separated by ','.
          endif.
        endloop.
        if l_val_string ne space.
          l_success = add_dim_restriction( i_param = l_val_string i_dimension = ls_cv-dimension i_clear = abap_true ).
          if l_success eq abap_false.
            concatenate 'Failed to successfully add Dimension' ls_cv-dimension into l_log_msg
            separated by space.
            cl_ujk_logger=>log( l_log_msg ).
            cl_ujk_logger=>log( 'Exiting Round Method' ).
            cl_ujk_logger=>empty_line(  ).
            raise exception type cx_uj_custom_logic
              exporting messages = et_message.
            exit.
          endif.
        endif.
      endloop.
      if l_success eq abap_false. exit. endif. - here the program exits and therefore doesn't do any rounding.
    If I comment this part the system rounds correctly but runs on all records in the cube which degrades performance a lot.
    Could you please advice further if it is possible to restrict the data region only to the submitted data?
    Best regards
    Jan

  • Storeing values in floate data type upto two decimal places

    Hi
    I want a float type field in my table but want to store value up to two decimal places.
    so what syntax i need to follow plz suggest.
    thanks

    it is not possible to store with Number datatype. if you are using the data to sho report, then change its format (like 45 to 45.00). if you want to store 45.00 in database, then you have to modify the datatype for that column. for this follow the following path
    1. Add a column of datatype Varchar2.
    2. Copy all the value of your number field to it.
    3. Drop the old column.
    4. However make sure that if you have used that column somewhare in arithmetic calculation, the modify it and use to_number function to do arithmetic opration.

  • Uploading Number with Two Decimal Places

    I am trying to import data from my excel file to table in the database using SQL Developer.
    It is working fine except that in my excel file I have data with two decimal places, but during import it shows only one decimal place. Is there any way I can import data with two decimal places?

    This works well with SQL Dev 1.5.X.
    Guess it would have been a bug in prior versions.

  • How can I limit a double value to two decimal place?

    How can I limit a double value to two decimal place?
    Java keeps on adding zero's to a simple double subtraction:
    1497 - 179.64 = 1317.3600000000001The answer must have been simply: 1317.36

    If the trouble is with output ...
    If the trouble is with value accuracy ...The trouble is with OPs understanding of and/or expectations of IEEE 754 floating point numbers. o_O
    [And it's probably a view (output) issue.]
    how can i actually use numberformat to cut those
    unwanted decimal places?Read the API - Puce already provided the link.

Maybe you are looking for

  • Why is the new iOS 6 so slow?

    Why is the my iPad 3 running so slow now I have updated to iOS 6. Also unable to access the app shop

  • How to communicate with third party bluetooth device using LAbVIEW

    Hi       I am trying to communicate with a third party bluetooth device using LabVIEW, I am using a bluetooth dongle. I am able to discover the device and able to open the connection by specifying the service as serial port. But after that when I am

  • Help with Lightrooom/Windows 8

    I just upgraded my computer to Windows 8, reinstalled Lightroom 4, and every time I go into the Develop Mode, Lightroom gives me an error and it shuts down.  I get the 'Adobe Photoshop Lightroom 64-bit has stopped working.  A problem caused the progr

  • Does not boot only beep error code 4-3-4-3 Model: M55 MT-M 8810-W8T

    Have a M55 MT-m 8810-W8T that does not display. Power i suppose is OK as it powers up and give beep code of 4-3-4-3. From what I found it is a PHOENIX BIOS Q3.07 OR 4.X version. From searching I can only find that it means that "Boot code was read OK

  • Reg Exp help needed (trouble with line breaks)

    Hello, I am attempting to parse a line of text with regular expressions. I am having difficulty with the line breaks. I want to divide the following line by the first '\n' char. For instance, I wan the output to be as follows: found 1: one found 2: d