CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2002
    Location
    Holland
    Posts
    279

    Format like function

    Hi,

    I was wondering if java supports a Format function like VB.
    Or do I need to program this myself?

    Thx,

    Jewe
    A VB programmer trying to stay alive in a Real C World

    If the hardware is so great.. why use software to correct it..?? It will only slow it down..
    Al is de hardware nog zo snel de software achterhaalt het wel

  2. #2
    Join Date
    Oct 2004
    Location
    India, Nickname: Diabolic Diablo
    Posts
    73

    Re: Format like function

    Format function like VB.
    Can u explain this function? Most of us here dont know VB.

    Kalyan Chakravarthy C.P.S


    "The difference between the possible and the impossible lies in a person's determination and patience."

  3. #3
    Join Date
    Mar 2002
    Location
    Holland
    Posts
    279

    Re: Format like function

    ok,

    with format you can specify the way a string is defined.
    for example:
    Format(Now,"YYYY-MM-DD") returns "2005-03-17"

    but also mlCount ( a long == int in java)
    Format(mlCount ,"0000") -->
    mlCount = 1 --> 0001
    mlCount = 34532 --> 34532

    Ik know in C you use printf functions for this but what is the defined way in Java?

    thx,

    Jewe
    (Java wannabe)
    A VB programmer trying to stay alive in a Real C World

    If the hardware is so great.. why use software to correct it..?? It will only slow it down..
    Al is de hardware nog zo snel de software achterhaalt het wel

  4. #4
    Join Date
    Apr 2001
    Location
    South Africa, Jo'burg
    Posts
    680

    Re: Format like function

    Hi,

    I'm not aware of any one function that can handle Dates and Numbers. However there is a NumberFormat class, with associated SubClasses, that handle formatting Numbers. For dates have a look at SimpleDateFormat.

    ( a long == int in java)
    Why does a long equal an int in java?

    Regards
    Byron

  5. #5
    Join Date
    Feb 2004
    Location
    USA - Florida
    Posts
    729

    Re: Format like function

    Java 1.5 introduced a C-like printf() method which emulates C's printf to output formatted strings (I would post the appropriate api page for printf, but Sun's website seems to be loading incredibly slowly for me).
    Hungarian notation, reinterpreted? http://www.joelonsoftware.com/articles/Wrong.html

  6. #6
    Join Date
    Mar 2002
    Location
    Holland
    Posts
    279

    Re: Format like function

    Quote Originally Posted by Bnt
    Why does a long equal an int in java?
    Sorry my mistake should be Long in vb = int in Java.
    A VB programmer trying to stay alive in a Real C World

    If the hardware is so great.. why use software to correct it..?? It will only slow it down..
    Al is de hardware nog zo snel de software achterhaalt het wel

  7. #7
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: Format like function

    for formatting dates, use SimpleDateFormat
    for formatting numbers, use a subclass of java.text.Format -> http://www.particle.kth.se/~lindsey/...malFormat.html
    or use java.util.Formatter (1.5 only?)

    in java 1.5, if your sole concren is printing numbers to the console, the System.out.printf() method uses C-like syntax, in combination with the Formatter class mentioned above to produce the output
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured