JSpinner and small values

This code don't works properly
spinner.setModel(new SpinnerNumberModel(3.0,null,null,0.1));This is the JSpinner but the number displayed in the included JTextField don't represent the correct value.
For example, in some case the number displayed is 3.3 but the number that returns spinner.getValue() is 3.30000000003.
I want that spinner.getValue returns 3.3
There is a solution to this problem?

Ayrton_4 wrote:
This code don't works properly
spinner.setModel(new SpinnerNumberModel(3.0,null,null,0.1));This is the JSpinner but the number displayed in the included JTextField don't represent the correct value.
For example, in some case the number displayed is 3.3 but the number that returns spinner.getValue() is 3.30000000003.
I want that spinner.getValue returns 3.3
There is a solution to this problem?Yes, you need desperately to learn about how all computers treat floating point numbers and work your programs accordingly. 3.30000000003 is a reasonable representation of 3.3 when working with floating point numbers. The key here is how to display this number correctly, and for this I often use the String.format( ) method which is similar to c's printf.
Please read in the tutorial section the parts about floating point math and you will understand.

Similar Messages

  • JSpinner and invalid values

    Hi guys !
    I have a JSpinner using the SpinnerNumberModel. I want to do the following:
    1- When the user enters an integer lower then the min value, it would automatically be set to the min value.
    2- When the user enters an integer higher then the max value, it would be set to the max value.
    3- When the user enters other characters (not integers), it would be set to the previous value (before the user typed).
    The default behavior of the SpinnerNumberModel is to just let it lay there when an invalid value is entered (until the focus leaves the spinner).
    I need to catch these invalid values (integer outside the range or non-integer characters) in other to respond correctly and change the value in the text field. Since these invalid values do not trigger the ChangeEvent event (thats the idea of the model I guess), I have tried catching them with an ActionEvent on the JFormattedTextField in the spinner but with no result.
    Or do I need to subclass the SpinnerNumberModel class ? And then how ?
    Or does it have to do with the JformattedTextField class ?
    Any idea someone ?

    I just realized if the user types in something that is not a number... it won't get committed... the spinner just reverts back to the last valid number. This is a good configuration (in case anyone ever reads this in the future):
        NumberEditor editor = (NumberEditor) spinner.getEditor();
        JFormattedTextField editorField = editor.getTextField();
        NumberFormatter formatter = (NumberFormatter) editorField.getFormatter();
        formatter.setOverwriteMode(true);
        formatter.setAllowsInvalid(true);
        formatter.setCommitsOnValidEdit(true);

  • JSpinner and very small values

    I Have a JSpinner and i wrote this code
    Double v = new Double(3.111110001111111111111111111111111111111111111);
    double min = 0;
    double max = 10;
    double step = 0.0001;
    SpinnerModel spinnerModel = new SpinnerNumberModel(v.doubleValue(),min,max,step);The are two problems
    1. The variable v is represented as '3,111'
    2. The step is incorrect... When i click on the up arrow, the number don't change. If I set the step to '0.001' all works correctly.
    There is a solution?

    If step = 0.0001 or step < 0.0001, the increment andthe decrement don't work
    correctly. The number displayed in the JSpinnerdon't change.
    If step = 0.001 all works correctly.
    Why if step = 0,001 it works, and if step = 0.0001it don't works correctly?
    It probly does work correctly, its just you are
    incrementing the 4th decimal place and the spinner
    only shows 3 decimal places.
    So you ARE incrementing, you just wont see it until
    after you increment 10 times and the 3rd decimal
    rounds up.If I increment 10 times the 4th decimal value, the 3rd decimal value don't change.
    Anyone can solve this problem?

  • MSO.DLL not installed with "office home and small business 2013"

    Hello,
    In my 32 bits application, I use the IInPlacePrintPreview interface on a "word.document" OLE object to show a preview of a word document.
    That's work fine with Office 2013 Standard Edition (32 bits) on a Windows 7 x64 Edition, but my application crash with "office home and small business 2013" (32 bits).
    I have noticed that the call to query the IInPlacePrintPreview interface on the OLE object load the mso.dll of Office into memory.
    The mso.dll is installed with the Office 2013 Standard Edition, but not with the "office home and small business 2013" Edition.
    I guess the problem is the lack of
    mso.dll.
    Do you know why the mso.dll is necessary for the preview of a word document ?
    How do I install and configure mso.dll on a
    "office home and small business 2013" edition ?
    Thanks for your help.

    Hi,
    You may try the ODT (Office Deployment Tool) to configure the Configuration.xml file and install the Office 2013 Home and Business edition.
    Please refer to the following steps:
    1. Downloading ODT from: http://www.microsoft.com/en-us/download/details.aspx?id=36778
    2. After downloading the ODT, there will be a Configuration.xml file ODT installed folder. Modify the Configuration.xml file as below so that we can download home business package. 
    <Configuration>
       <Add SourcePath="D:\Office\" OfficeClientEdition="32" >
        <Product ID="HomeBusinessRetail">
          <Language ID="en-us" />
        </Product>
      </Add>  
       <Updates Enabled="TRUE" UpdatePath="D:\Office\" /> 
       <Display Level="None" AcceptEULA="TRUE" /> 
       <Logging Path="%temp%" /> 
       <Property Name="AUTOACTIVATE" Value="1" />  
    </Configuration>
    For more information regarding to the ODT, you can refer to the following link:
    http://technet.microsoft.com/en-us/library/jj219422(v=office.15).aspx
    Should you have any questions, please feel free to let me know. many thanks!
    Michael Bai
    Office Client Support

  • How to create a PDF with substituted key-value and table-values using a template language

    I have about 50 key-values and 10 table-values that I want to substitute into a formatted report template (language can be anything standard, would create a small number of these templates) and then use an Adobe tool to substitute the values into the template and produce a PDF. Preferably the template language would permit some basic conditional logic (if <key #> has value <value> then <show key label here> and <key value here> in close spatial proximity on the form) and permit embedding of a static graphic logo, text with fonts/styles, etc. to produce a polished report but also handle pagination (e.g. enable page breaks or numbering) to be handled automatically.
    What is a recommended template language and product to accomplish this?

    Are you thinking of something like a blank form that you can enter information into, save, and send to another user? If so, what you want is possible. If you want more information, post again and include more details about how you want to use it and how the recipient will use it.

  • How to get Max and Min value entered in a DOS console?

    Hi there? I wanted to get the Maximum and Minimum value that I entered in a console and displays it. This is using the java.lang.Math class and using it's method max and main. please help. thanks - new to java

    Sounds like you need very basic advice: Start with the tutorials: http://java.sun.com/docs/books/tutorial/index.html
    And if the algorithm is the problem:
    - Make two variables that hold the current maximum and minimum value
    - whenever a value is entered, compare it with the minimum, if it is smaller, set the minimum to that value
    - ditto with maximum
    at the end the two variables contain the maximum and minimum values.

  • ABAP program to neutralize  0Unit value and 0quantity value

    Hi all,
    I'm not expert in ABAP, and i would like implement a small abap program (routine)in my cube.
    I would like neutralize the 0UNIT value and 0QUANTITY value only when 0VTYPE = 1 or 2 :
    <b>in other words, if 0vtype = 1 or 4 then 0unit = space and 0quantity = 0
    b]
    Can you tell me please <b>how and where</b> write the ABAP program please ?
    Message was edited by:
            Pontoise Pontoise
    Message was edited by:
            Pontoise Pontoise

    Hi,
    I amnt able to understand your requirement. But the code for which you asked is simple.
    If 0vtype = 1 or 0vtype = ' '.
    0unit = space.
    0quantity = 0.
    endif.
    Regards
    Aneesh.

  • JSPinner and floating point quirk

    Please test these spinners only with their down arrow buttons to reach minimum value of each. When the number of fraction columns are 5,10 and 12, spinner stops at one step before the real minimum. They don't go to the real minimum. Why could this happen?
    import javax.swing.*;
    import java.text.*;
    public class SpinnerQuirk{
      public static void main(String[] args){
        Box panel = new Box(BoxLayout.X_AXIS);
        double fraction = 0.01;
        double base = 1.0;
        String fmt = "#0.00";
        for (int i = 2; i < 14; ++i){
          DecimalFormat df = new DecimalFormat(fmt);
          Box box = new Box(BoxLayout.Y_AXIS);
          JSpinner spinner = new JSpinner();
          SpinnerNumberModel spinnerModel
            = new SpinnerNumberModel(base + fraction,
                                     base + fraction - fraction * 101,
                                     base + fraction + fraction * 99,
                                     fraction);
          spinner.setModel(spinnerModel);
          spinner.setEditor(new JSpinner.NumberEditor(spinner, fmt));
          JLabel label = new JLabel("min = "
              + df.format((base + fraction - fraction * 101)));
          box.add(spinner);
          box.add(label);
          panel.add(box);
          fraction = fraction / 10.0;
          fmt += "0";
        JOptionPane.showMessageDialog(null, panel);
        System.exit(0);
    }

    Thanks. I think I have found the root cause of the problem. That is, there's no effective communications between java.text formatting and javax.swing.text one(*). A bad example of a bureaucratic sectionalism at Sun?
    (*: Because DecimalFormat does the right job given the same format string and same value.)
    Japanese: tate wari
    Englisn: divided vertically
    Edited by: hiwa on Oct 5, 2007 11:18 AM

  • Min Lot Size and Rounding value

    Hello MM  Gurus
    need a small help!
    I m a bit confused regarding the  use of Min lot size and Rounding value in material master "MRP 1" view..
    can some body teach me a detailed functionlity for both..
    As both serve the purpose ..for e.g. my requirement is 7 and min lot is 10 system will create proc.proposal for 10
    in similar way if i use rounding value as 10 , then als system will create proc.proposal for 10 only even if requirement is 7.
    grateful if you could pl expain me the functionality of both...
    another query..if I use Min lot size in material master will the same will serve the puspose of  <b>min order qty ( maintained in PIRs)</b>
    i'lll appriciate with good reward points...thanks in advnace
    Br
    Sumit

    Helo Guys..
    Thanks for valuable inputs..
    i have assigned the appropriate rewards ..
    pl clear my this doubt also
    e.g. for a materials
    Min Lot size - 40
    Rounding value 25
    requirement is for - 35
    will it be 40 or 50 ..i understand 50..
    j
    ust anothe rquery..pl treat this separate issue..and separate rewards will be given
    <b>can I use max stock level w/o use of  lot size "HB"</b>
    e.g. if my max stock level is 80
    and min lot size is 30 and current stock is 60
    what'll be my proc proposal created by MRP , i dont want system to cross 60 stck,,
    Thanks in advance
    BR
    Sumit

  • Conditional formatting: greatest and lowest values in a column?

    I have a column of data, with about 30 rows of values. Is it possible to setup conditional formatting so that Numbers highlights the top three highest values and the lowest three values in the column?
    thanks!

    How's this:
    1. Create the second table for the large and small formulas. I did one column, you should be able to copy it to the rest of them.
    2. Create the conditional format for the first data cell in the first row of your data table (go to the cell inspector and choose "show rules" to get to the conditional formatting pane).
    3. Select the cell, Copy Style, select all the other data cells in the row and Paste Style to copy that conditional format to the other columns. At this point, the conditional format in the other columns will be incorrect (they will all refer to the large/small values for the first column), you'll have to modify each manually so they refer to the correct cells in the "large/small" table.
    4. Copy Style and Paste Style each of those conditional formats to the rest of the cells in each column.
    One caveat: You may get more than three smallest/largest values highlighted under certain conditions. For instance if you have four 1's and "1" is your smallest value, all four would get highlighted. If you have two 1's and two 2's, and they are your smallest values all four would get highlighted. If you have 1,2,3,3 and they are your smallest values you would also get four highlighted. Similar case for the largest values. It doesn't appearthat this would be a problem for your data.

  • Open a web page and pass values from a java file

    Hi,
    I need to open a web page and pass values in the text boxes.
    Finally submit needs to be triggered. All this needs to be done from a java file. i.e instead of entering my values in a web page and submit, i need to do it from my java file..
    Any inputs so that I proceed in the right direction..or is there any alternate way to achive this ??
    Thanks in advance..
    Sid

    I hava found a lines of jaa that can open a URL , lets say www.net.java
    You can open it writable or not.
    It is half of the job you need.
    If you are interested.
    I am wrinting a program to print a URL , and have developed this small
    code.
    Angel Portal

  • JSpinner min/max values

    I'm working on a project that requires a JSpinner to have a minimum value of 0 and a maximum value of 10. Is there a method that allows a min/max value to be set? I did a search for threads regarding JSpinner and I didn't seem to find anything that answered my question. Thanks in advance.

    [url http://java.sun.com/docs/books/tutorial/uiswing/components/spinner.html#standard]How to Use Spinners

  • JSpinner and BigDecimal , what am i doing wrong?

    hi,
    i'm trying to use a JSpinner to let the user input currencies.
    all my currencies are represented by BigDecimals.
    SpinnerNumberModel provides the following methodn which let's me think i can use BigDecimals in the spinner component:
    setStepSize(Number stepSize)
    The following code fails though :
    JSpinner spinner = new JSpinner();
    SpinnerNumberModel model = new SpinnerNumberModel();
    model.setStepSize(new BigDecimal("0.01");
    model.setValue(new BigDecimal("0.00");
    spinner.setModel(model);the spinner arrows don't work , and any value i enter is rejected
    what could be the problem ?

    From the SpinnerNumberModel API documentation:
    Internally, there's only support for values whose type is one of the primitive Number types: Double, Float, Long, Integer, Short, or Byte.

  • JDK1.4 JSPinner and DateFormatSymbols

    Hi,
    I have a problem with DateFormatSymbols().getWeekdays(); use in JSPinner and JCOmboBox
    The getWeekdays() method returns a STring[] containing the nameof the days (sunday, ...) in a localized way. I want to use these names inside a JSPinner or a JCombobox. The names are properly inserted, but there is a 'empty' value containing no string, even after calling the setEditable(false)
    any idea on how to remove that empty 'day'??
    thanks,
    vincent

    Store the String[] in a local copy and remove from that local copy manually the "empty day". Then use the manipulated local copy in the JComboBox ...

  • MaskFormatter with JSpinner and DateEditor?

    Hi,
    I'm trying to apply a MaskFormatter to the DateEditor on a JSpinner. We want the ability to both manually edit the fields by hand AND/OR click the up/down arrows.
    The one gotcha is that when manually entering the values, we want to set a mask on the field so the user doesn't have to type in the ":" when separating the time fields. Right now, when they can delete all the text in the spinner textfield.
    I've dug through the source code of JSpinner and it appears that I should be able to get the editors JFormattedTextField and set the MaskFormatter as part of the AbstractFormatFactory. But all I end up with is a blank JSpinner and I can't type in the textfield.
    Below is my code:
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.util.Calendar;
    import java.util.Date;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JSpinner;
    import javax.swing.SpinnerDateModel;
    import javax.swing.SpinnerModel;
    import javax.swing.text.DefaultFormatterFactory;
    import javax.swing.text.MaskFormatter;
    public class MaskedFieldTest {
         public static void main(String[] args) {
              final JFrame f = new JFrame("Textfield demo");
              f.setDefaultCloseOperation(f.DISPOSE_ON_CLOSE);
              f.addWindowListener(new WindowAdapter() {
                   public void windowClosed(WindowEvent e) {
                        System.exit(0);
              f.setSize(250, 70);
              try {
                   // Create a spinner
                   JSpinner spinner = new JSpinner();
                   // Set up a dummy calendar for the model
                   Calendar calendar = Calendar.getInstance();
                   Date initDate = calendar.getTime();
                   calendar.add(Calendar.YEAR, -100);
                   Date earliestDate = calendar.getTime();
                   calendar.add(Calendar.YEAR, 200);
                   Date latestDate = calendar.getTime();
                   // Set the model
                   SpinnerModel dateModel = new SpinnerDateModel(initDate, earliestDate, latestDate, Calendar.YEAR);
                   spinner.setModel(dateModel);
                   // Create the dateeditor using the time format we want displayed in the spinner
                   JSpinner.DateEditor dateEditor = new JSpinner.DateEditor(spinner, "hh:mm:ss a");
                   // Create a mask for editing so we don't have to manually add the :
                   MaskFormatter fmt = new MaskFormatter("##:##:## UU");
                   // Get the factory from the editor and set the maskformatter for the editing portion
                   DefaultFormatterFactory form = (DefaultFormatterFactory)dateEditor.getTextField().getFormatterFactory();
                   form.setEditFormatter(fmt);
                   // Finally, assign the editor to the spinner
                   spinner.setEditor(dateEditor);
                   // Display the panel
                   JPanel panel = new JPanel();
                   panel.add(spinner);
                   f.getContentPane().add(panel);
                   f.setVisible(true);
              } catch (java.text.ParseException e) {
                   e.printStackTrace();
    }If you run the code, you'll just get an empty JSpinner and you can't do anything in the textfield even though it is enabled.
    I'm running JDK.1.4.2_09 on Windows XP SP2
    Has anyone used a MaskFormatter with a DateEditor on a JSpinner before?
    Thanks,
    - Tim

    see weebib's post here
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=581804

Maybe you are looking for