What is the Best Practice to display number field without a thousands separator (comma or period, depending on locale)?
I have rejected the following ideas:
- Text field, because I have to write Validation Rule for number. Performance will be affected.
- Phone field, because in case of editing in UI, Salesforce changes 10 digit numbers to match US formatting.
I am looking for best practice, because no clean solution is available. All are dirty solutions.
Edit:
- There is no decimal
- I won’t use the field on VF pages; I’ll use the field in reports, and hence don’t want the comma in my report tab – if the comma isn’t there on the report tab, it won’t reflect in the downloaded XLS too
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Create a new custom field, where type is “formula” and the formula return type is “text”.
In the formula, use the TEXT() function, and pass the existing number field value into this formula. For example, if your number field is MyNumber_c then your formula would be: TEXT( MyNumber_c )
Your users will enter values into the existing number field, but you can use the formula field (which doesn’t display thousands separators) in reports, list views etc.
Method 2
You can use apex:outputText tag to format the output. Try this out:
<apex:outputText value="{0, number, 000000.00}"> <apex:param value="{!numberfield}" />
Method 3
easilydone use <apex:inputtext>
and <apex:outputtext>
instead of <apex:inputfield>
Method 4
One thought that comes to mind is to make it a number field data type, but then use Visualforce to render it.
On your Visualforce, bind the output to apex:outputText instead of apex:outputField this should remove all formatting from the number.
It would require a relatively small amount of VF, that you could then embed in a section of your page layout. Still a bit ugly, but it should work.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0