This discussion is archived
5 Replies Latest reply: Apr 3, 2013 11:34 PM by gimbal2 RSS

doubt in Decimal Format  class

user575089 Newbie
Currently Being Moderated
What is the difference between ....


(1)DecimalFormat fff = new DecimalFormat("*#####*.00");

AND

(2) DecimalFormat fff = new DecimalFormat("*###*.00");



I know # is digit ....



I want to know where I should be using (1) and where I should be using (2) ..... need an example .
  • 1. Re: doubt in Decimal Format  class
    rp0428 Guru
    Currently Being Moderated
    >
    What is the difference between ....

    (1)DecimalFormat fff = new DecimalFormat("#####.00");

    AND

    (2) DecimalFormat fff = new DecimalFormat("###.00");

    I know # is digit ....
    >
    Well if you know that '#' is a digit then you should know what '#####' or '###' means.

    Post your answer here.

    The best way to learn is to first check the Javadocs: http://docs.oracle.com/javase/6/docs/api/java/text/DecimalFormat.html
    And then to actually TRY things to see what the result is.
    >
    # Number Yes Digit, zero shows as absent
    >
    So a '#' represents a digit but any leading '0's will NOT be present.

    Do not be afraid of breaking Java by actually trying things.

    Format some sample values using both of those and see what happens. Try each format with numbers that have 1, 3, 5 and 7 digist to the left of the decimal.

    Post your results here.
    >
    I want to know where I should be using (1) and where I should be using (2) ..... need an example .
    >
    Your tests above will give you the answer to that. You use '1' when you need the result that '1' produces and you use '2' when you need the result that '2' produces.
  • 2. Re: doubt in Decimal Format  class
    gimbal2 Guru
    Currently Being Moderated
    rp0428 wrote:
    Your tests above will give you the answer to that. You use '1' when you need the result that '1' produces and you use '2' when you need the result that '2' produces.
    How can anyone argue with that logic! :)

    Its still the correct answer to the question of course. You use something when it makes sense to use it. It will only start to make sense when you understand it. So understanding it all is step 1. Perhaps the javadoc isn't clear enough, then simply google for 'java decimalformat example' to get more help.
  • 3. Re: doubt in Decimal Format  class
    user575089 Newbie
    Currently Being Moderated
    rp0428 wrote:
    >
    What is the difference between ....

    (1)DecimalFormat fff = new DecimalFormat("#####.00");

    AND

    (2) DecimalFormat fff = new DecimalFormat("###.00");

    I know # is digit ....
    >
    Well if you know that '#' is a digit then you should know what '#####' or '###' means.

    Post your answer here.
    You are confusing more. ..... Will you be kind enough to explain in simple words ?


    I have a number 123456789 ...so it is ### or ######### ?

    (reason of confusion is whether # connects to multiplicity of digits)



    The best way to learn is to first check the Javadocs: http://docs.oracle.com/javase/6/docs/api/java/text/DecimalFormat.html
    And then to actually TRY things to see what the result is.
    >
    # Number Yes Digit, zero shows as absent
    >
    So a '#' represents a digit but any leading '0's will NOT be present.
    Can I write more # than the actual number of digits ? for example, is it correct if I write ######## to represent 678 ?
  • 4. Re: doubt in Decimal Format  class
    EJP Guru
    Currently Being Moderated
    I have a number 123456789 ...so it is ### or ######### ?
    >
    # Number Yes Digit, zero shows as absent
    >
    So a '#' represents a digit but any leading '0's will NOT be present.
    Can I write more # than the actual number of digits ? for example, is it correct if I write ######## to represent 678 ?
    What part of "zero shows as absent" and "leading '0's will not be present" don't you understand? How simple do the words have to be exactly?
  • 5. Re: doubt in Decimal Format  class
    gimbal2 Guru
    Currently Being Moderated
    EJP wrote:
    I have a number 123456789 ...so it is ### or ######### ?
    >
    # Number Yes Digit, zero shows as absent
    >
    So a '#' represents a digit but any leading '0's will NOT be present.
    Can I write more # than the actual number of digits ? for example, is it correct if I write ######## to represent 678 ?
    What part of "zero shows as absent" and "leading '0's will not be present" don't you understand? How simple do the words have to be exactly?
    And why are you still not experimenting?

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points