corejava

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arunareddy
    New Member
    • May 2007
    • 1

    #1

    corejava

    hi,
    can u tell me how to convert a double value(10.0) to String value "10.00"
  • rsrinivasan
    New Member
    • Mar 2007
    • 221

    #2
    Hi,

    You can convert double value to string value by using valueOf() function of String class.

    For Example:

    public class ConvertDouble
    {
    public static void main(String[] args)
    {
    double d=4.0;
    String str= String.valueOf( d);
    System.out.prin tln(str);
    }
    }

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by arunareddy
      hi,
      can u tell me how to convert a double value(10.0) to String value "10.00"
      If you want those two decimal digits you have to use a DecimalFormat.

      kind regards,

      Jos

      Comment

      • parthpatel
        New Member
        • Apr 2007
        • 14

        #4
        update

        class convert {
        double d = 4.0;
        String s = ' ' + d;
        System.out.prin tln(s);
        }
        Last edited by parthpatel; May 12 '07, 09:17 AM. Reason: Problem writing script

        Comment

        • parthpatel
          New Member
          • Apr 2007
          • 14

          #5
          class convert {
          public static void main(String args[]){
          double d = 4.0;
          String s = ' ' + d;
          System.out.prin tln(s);
          }
          }

          Comment

          Working...