• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

printf method

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


can you ecplain what is work of 1 in this code (01.2f)???
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the Javadoc...

  • The format specifiers for general, character, and numeric types have the following syntax:

  • %[argument_index$][flags][width][.precision]conversion



    So, I guess it is supposed to be the width?

    Henry
     
    Ranch Hand
    Posts: 423
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    The format specifier has syntax:

    %[flags][width]conversion


    0 - is flag (result will be 0-padded)
    1 - is width (the minimum number of characters to be written to the output)

    look here:
    http://java.sun.com/j2se/1.5.0/docs/api/java/util/Formatter.html
     
    vineet walia
    Ranch Hand
    Posts: 140
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Ireneusz Kordal wrote:The format specifier has syntax:

    %[flags][width]conversion


    0 - is flag (result will be 0-padded)
    1 - is width (the minimum number of characters to be written to the output)

    look here:
    http://java.sun.com/j2se/1.5.0/docs/api/java/util/Formatter.html



    it is not width try change argumnet 7 and then 7267 ?
     
    Ranch Hand
    Posts: 64
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    vineet walia wrote:it is not width try change argumnet 7 and then 7267 ?


    It is width. You can call it "minimum width". If argument's width extends it, it is ignored. Try to put 010 instead of 01, see the difference.
     
    Greenhorn
    Posts: 10
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    It is the Width, Try removing 1 and run it with

    System.out.printf("%0.2f",new Double(7267));

    Exception in thread "main" java.util.MissingFormatWidthException: 0.2f
     
    Bartender
    Posts: 6663
    5
    MyEclipse IDE Firefox Browser Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    For more information on exception types that can be thrown look here

    http://java.sun.com/j2se/1.5.0/docs/api/java/util/Formatter.html#detail
    reply
      Bookmark Topic Watch Topic
    • New Topic