Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: compile time error

  1. #1
    Junior Member
    Join Date
    Oct 2018
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default compile time error

    DecimalFormat fmt = new DecimalFormat(“0.##”);
    double value = fmt.format(“23.457”);
    System.out.print(value);

    After writing this, i get a compile time error. Why is that?

  2. #2
    Member John Joe's Avatar
    Join Date
    Jun 2017
    Posts
    277
    My Mood
    Amused
    Thanks
    8
    Thanked 19 Times in 19 Posts

    Default Re: compile time error

    1. fmt.format() will return a String, so should be declare as String vaue instead of double.
    2. Argument for fmt.format is doublle, not string.

    So the correct code should be
    DecimalFormat fmt = new DecimalFormat("0.##");
    String value = fmt.format(23.457);
    System.out.print(value);
    Last edited by John Joe; October 5th, 2018 at 01:59 AM.
    Whatever you are, be a good one

  3. The Following User Says Thank You to John Joe For This Useful Post:

    Elio.alsayah (October 6th, 2018)

Similar Threads

  1. Replies: 6
    Last Post: September 24th, 2014, 11:04 AM
  2. Replies: 3
    Last Post: November 30th, 2013, 05:52 PM
  3. compile error
    By silverpen10 in forum What's Wrong With My Code?
    Replies: 22
    Last Post: January 12th, 2013, 11:15 AM
  4. Error while compile
    By when im gone in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 7th, 2012, 10:53 AM
  5. Compile Error, tried everything please help
    By cdub0 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 17th, 2011, 03:31 AM