Results 1 to 5 of 5
  1. #1
    talia is offline Member
    Join Date
    Dec 2011
    Location
    London
    Posts
    11
    Rep Power
    0

    Default help with math.round

    I got this code, am simply trying to cap the decimal place to 2 in the final result

    total1 = Double.parseDouble(PriceNoVatTextField.getText());
    total2 = ((total1 / 100) * 20)*100;
    total3 = Math.round(total2); ---------------------------I get an error here stating java.lang.Double required; found long tried converting but not sure what is required there

    //total3 = total1 + total2;

    PriceWithVatTextField.setText(String.valueOf(total 3));

    anyone can shed a light on this:)

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: help with math.round

    Double required;
    Please post the full text of the error message.

    What data types are the total variables? How are they defined?
    Last edited by Norm; 12-14-2011 at 01:51 PM.

  3. #3
    talia is offline Member
    Join Date
    Dec 2011
    Location
    London
    Posts
    11
    Rep Power
    0

    Default Re: help with math.round

    these are the totals, they r all doubles:
    private Double total1 = 0.0;
    private Double total2 = 0.0;
    private Double total3 = 0.0;

    I tried using the total2.doubleValue() before but still giving me the same error in the Math.round line...

    am not sure how to convert it now, or into what... as far as I know they are all Doubles...

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: help with math.round

    Read the API doc for the round() method to see what kind of value it returns and whether it does what you want.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default Re: help with math.round

    @abhi7080
    Create your own thread for your question. Do not hi-jack someone else's thread

Similar Threads

  1. Round of help
    By micolord in forum New To Java
    Replies: 5
    Last Post: 10-08-2011, 05:56 AM
  2. Using math.round
    By Hype in forum New To Java
    Replies: 3
    Last Post: 01-30-2011, 11:57 PM
  3. Create Math.sin without math.sin
    By vudoo in forum New To Java
    Replies: 11
    Last Post: 12-07-2010, 06:23 AM
  4. going round and round in class..
    By sonny in forum New To Java
    Replies: 52
    Last Post: 04-02-2010, 10:56 AM
  5. How to round a double?
    By Valeriano in forum New To Java
    Replies: 1
    Last Post: 05-31-2007, 03:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •