I am having problems with number formatting. Here is the situation:
I have a number that could be 999,999,999 or .0001. In the code, any number greater than or equal to 1 is round to the nearest whole. Anything less is rounded to 4 decimal places. I need the format to reflect this change.
In theory, from the documentation, the following should work in the format attribute on the field definition in the form:
#,###.#
but it does not. I have gotten percentages and I have gotten just no decimal places, but not what I am aiming for.
Check the actual fields/tables using a backend tool like mySQL administrator. I have seen servoy create a number field and in the backend it can create either a float, decimal, or double type number!!
This number type may be influencing how it can be formatted. I stay away from decimal types and prefer float/double. Always watch this when creating new number dataproviders using mySQL.
Tough one. The only thing you can do if you want to be able to display both options with one field is:
#,###,###,###.####
Notice that you have to have as many # characters as places you expect to have in your number.
Unfortanately, this will always display four zeros after the decimal place for your “integers”.
Alternately, you can use two different fields to display the number - each field with a different format. Then show the correctly formatted field and hide the other via a method run on the onRecordSelect event. This will only work though if you are showing one record at a time.
david:
Alternately, you can use two different fields to display the number - each field with a different format. Then show the correctly formatted field and hide the other via a method run on the onRecordSelect event. This will only work though if you are showing one record at a time.
Or in that case use a calculation and format it conditionally to the given value in code.