Results 1 to 4 of 4
  1. #1
    emad7105 is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Question Dealing with floating-point in double and String and convert it to String

    My question is a little bit simple but makes me crazy!

    Suppose that:

    Java Code:
    long number_long = 1100903354159269000;
    I want to show this number as String in output like "1100903354.159269000". To do this, I convert the number to String and perform some basic concatination and it is ok. But I need this new number as Long or Float exactly like this floating point to do some mathematical functions.

    How can I do this? The place of floating point is fixed, but the left part of it may increase.
    Could you tell me which one is better, Float or Double? How can I convert the result to String with this floating point?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,751
    Rep Power
    19

    Default Re: Dealing with floating-point in double and String and convert it to String

    If you need accuracy use BigDecimal.
    Not sure what you mean by the point being fixed.

  3. #3
    mkarthik90 is offline Member
    Join Date
    Feb 2012
    Posts
    62
    Rep Power
    0

    Default Re: Dealing with floating-point in double and String and convert it to String

    I you need to convert the string to a Float better use the float class constructor as below

    String str="111.00001";
    Float f = new Float(str);

    The string will be converted to a float and you can use for furthur processing.

  4. #4
    emad7105 is offline Member
    Join Date
    Feb 2012
    Posts
    3
    Rep Power
    0

    Default Re: Dealing with floating-point in double and String and convert it to String

    Quote Originally Posted by Tolls View Post
    If you need accuracy use BigDecimal.
    Not sure what you mean by the point being fixed.
    WOW! I have not ever seen BigDecimal class! Wonderful and perfect!!
    I've done it, it's working, yessssss



    Quote Originally Posted by mkarthik90 View Post
    I you need to convert the string to a Float better use the float class constructor as below

    String str="111.00001";
    Float f = new Float(str);

    The string will be converted to a float and you can use for furthur processing.
    Thanks for your reply, but I think the number will become greater than float type variable lenght. BigDecimal meet my needs.

Similar Threads

  1. Replies: 8
    Last Post: 11-04-2011, 08:30 PM
  2. Displaying floating point value
    By NuxlyStardust in forum New To Java
    Replies: 11
    Last Post: 04-14-2011, 06:40 PM
  3. Convert from string to double
    By Lord ice in forum New To Java
    Replies: 4
    Last Post: 12-12-2010, 05:27 PM
  4. convert String to Double
    By azurovyhrosik in forum CLDC and MIDP
    Replies: 5
    Last Post: 10-22-2008, 02:46 AM
  5. convert string to a double?
    By javaMike in forum Advanced Java
    Replies: 2
    Last Post: 11-27-2007, 03:10 AM

Tags for this Thread

Posting Permissions

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