Results 1 to 3 of 3
  1. #1
    itaipee is offline Member
    Join Date
    Dec 2008
    Posts
    99
    Rep Power
    0

    Default NumberFormat which leave fractions as they are

    I need a textfield, ( JFormattedTextField) with number format that follow this rule for fractions:

    your input can be "3.3" or "4.40" and the input will stay that way.
    3.3 will not become 3.30, and 4.40 will not become 4.4
    However -

    in the default of the numberFormatted - the zero after the fraction in "4.40" is removed so I got "4.4"

    if I use the method "f1.setMinimumFractionDigits(2)"
    then 3.3 becomes 3.30

    as there any way the number format will stay as it is ?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default

    Display, and handle it, as a String rather than a number?
    This is, of course, presuming the system doesn't modify this value itself.

  3. #3
    zweibieren is offline Senior Member
    Join Date
    Aug 2009
    Location
    Pittsburgh, PA
    Posts
    284
    Rep Power
    5

    Default

    Create a new object for these integer values.
    Internally the object stores the value as a String.
    The constructor or setValue() method would
    parse the value with NumberFormat to check that it is a number.
    The object would have two output methods:
    toNumber() and toString(), returning double and String, respectively.
    The screen display would use toString() while computations use toNumber().

    (Spreadsheets use this sort of object for their cells.)

Similar Threads

  1. Leave management System
    By anji4u_19 in forum Suggestions & Feedback
    Replies: 24
    Last Post: 04-05-2010, 06:03 PM
  2. using numberformat
    By roaan in forum New To Java
    Replies: 3
    Last Post: 07-02-2009, 04:28 AM
  3. NumberFormat is abstract?
    By DrKush in forum New To Java
    Replies: 4
    Last Post: 03-27-2009, 07:54 AM
  4. How do I reduce Fractions in this program?
    By Popedreadlock in forum New To Java
    Replies: 8
    Last Post: 12-08-2008, 12:28 AM
  5. Parsing a number using a NumberFormat
    By Java Tip in forum java.text
    Replies: 0
    Last Post: 04-16-2008, 11:03 PM

Posting Permissions

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