I realized an invoicing application in J2EE(jsp,servlet), after having finished my program and tests, I noticed the following error: my sql server table FACTURE contains: Price NUMERIC (6,2) the user enters 333.33 is good but WHENE HE enters 333333 is the error. is there any other type in sql server that allows me to enter data in this way without errors MOSTLY I WANT DISPLAY WITH DECIMAL,I tested type float but it doesn't allow me to display zeros at the end.
2 Answers
You need to format it as a string. Look into NumberFormat
or if you're working with some web framework there is more than likely some framework specific way of doing it, such as <fmt:formatNumber/>
tag for JSPs or <f:convertNumber/>
for JSF.
Update
It seems I misread the question, my appology. You're asking about validating data. In that case you either need to write the validation code yourself and based on the validation logic determine whether to persist the data or display an error message. Again, frameworks will have facilities that will make this easier. Primefaces has a neat one <p:inputMask/>
. For JSF, you'd use a combination of a converter and validators, see this for an extensive discussion. I'm sure other web frameworks have similar facilities.

- 3,415
- 2
- 18
- 36
-
In the database you declare it the type it makes sense for the data to be. Then when you query you'll get one of the java data types (long, double, etc.) number formatting will work with any. – rdcrng Aug 15 '13 at 13:28
-
thanks, it limited my search fields, but i did not find the suitable régular expresiion for my probléme. – najeh22 Aug 16 '13 at 09:13
-
I find another solution with numeric plugin in jquery :http://jsfiddle.net/vandalo/fhYAs/ – najeh22 Aug 18 '13 at 17:56
Store it as a float in the database and then use a NumberFormat.getCurrencyInstance().format() when displaying the value.

- 131
- 1
- 2
- 7