Results 1 to 2 of 2
  1. #1
    marall80 is offline Member
    Join Date
    Apr 2011
    Posts
    1
    Rep Power
    0

    Unhappy java method for number formatting

    i have a field(price) ,sometimes it is decimal sometimes it is string.

    i want to format it with NumberFormat class like (123,356,565)

    i know that i shoud make a method for this but i dont know how

    i have a class like this i should add my method to it.

    this method makes the first character of str upper case.

    please help me



    public class StringUtils {
    private static NumberFormat nf = NumberFormat.getInstance();

    /**
    * makes the first character of str upper case.
    */
    public static String firstCharUp(String str) {
    if (str == null)
    return null;
    if (str.length() == 0)
    return str;
    StringBuilder sb = new StringBuilder(str);
    char firstChar = sb.charAt(0);
    sb.setCharAt(0, Character.toUpperCase(firstChar));
    return sb.toString();
    }

    }

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

Similar Threads

  1. String and number formatting
    By computerbum in forum New To Java
    Replies: 1
    Last Post: 04-27-2010, 05:06 PM
  2. Number formatting
    By gandalf5166 in forum New To Java
    Replies: 7
    Last Post: 03-26-2010, 02:54 AM
  3. Formatting isbn number with Math.random()
    By dns77x7 in forum New To Java
    Replies: 11
    Last Post: 09-21-2008, 06:02 PM
  4. Formatting a number to currency
    By Java Tip in forum java.text
    Replies: 0
    Last Post: 04-16-2008, 10:59 PM
  5. Correct Number formatting
    By paul in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 04:59 AM

Posting Permissions

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