Below is my code. My JFormattedTextField is numberField. I need a format (pattern) for the following:

100.00000 needs to appear as 100.000
10000.123456 needs to appear as 10000.123
1.055E9 needs to appear as 1055000000.000
211.E9 needs to appear as 211000000000.000

is there a pattern to do this?

Thank You

NumberFormatter doubleFormatter = new NumberFormatter(new DecimalFormat("#0.000#"));doubleFormatter.setAllowsInvalid(false);numberField.setFormatterFactory(new DefaultFormatterFactory(doubleFormatter));numberField.setColumns(10);numberField.setValue(0.0);

I think you want this format "#0.000" which will have exactly 3 digits after zero always even if only have precision to tenths or hundreds place. Additionally, will always have a digit in ones place even if value is less than one.

NumberFormatter doubleFormatter = new NumberFormatter(new DecimalFormat("#0.000"));doubleFormatter.setAllowsInvalid(false);numberField.setFormatterFactory(new DefaultFormatterFactory(doubleFormatter));numberField.setColumns(10);numberField.setValue(0.0);

So your one error is the extra # at the end as it would be a fourth digit after decimal and if you remove one of the zeros and have # instead then numbers with less than three digits would only go out two places. Therefore, you have to remember that 0 is used in pattern to represent a digit that will be included no matter what either as value or zero. # are only included when have non-zero value.

0

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

The one problem with what I have is that if I have a large number like

2.23E19 in my database when the value populates my JFormattedTextField it appears as 0 for some reason. It does not do this for smaller numbers though.

The value is correct when it comes out of the database it goes to 0 when I attempt to use the correct value to set the text for the JFormattedTextField. It's correct before I set the JFormattedTextField but then the textfield displays a 0 after I use the correct number and attempt to set it. If I use a smaller number like 1.0E5 it works OK for some reason.

Actually I did get it to work I was using numberField.setText then I switched over to numberField.setValue apparently the first way was not using the Formatter correctly.

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all. Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET â€¦

Introduction
This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used byâ€¦

Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Booleâ€¦

Viewers will learn about the regular for loop in Java and how to use it.
Definition:
Break the for loop down into 3 parts:
Syntax when using for loops:
Example using a for loop: