10

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:

  1. Text field, because I have to write Validation Rule for number. Performance will be affected.
  2. 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:

  1. There is no decimal
  2. 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
  • 3
    Do you have Decimal Places = 0? – Sergej Utko Jan 21 '13 at 11:50
  • @mast0r, no decimal places – Shumon Saha Jan 22 '13 at 10:40
15

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.

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}" />

  • Thank you for your answer, but I need the functionality in downloading XLS reports too. – Shumon Saha Jan 21 '13 at 12:11
  • well in that case, the best option for you is to have a text field and then a single line validation rule with: (NOT(ISNUMBER(yourStringfield))), show the error message. – Shailesh Deshpande Jan 21 '13 at 12:26
2

easilydone use <apex:inputtext> and <apex:outputtext> instead of <apex:inputfield>

  • easilydone use <apex:inputtext> and <apex:outputtext> insted of <apex:inputfield> – sheetal kothari Aug 18 '15 at 6:50
  • 1
    Sheetal, you can use the {}code format button in the editor to make xml,html or visualforce show up. I've gone ahead and done that for you now. Also: explaining your answer (why this works) will also increase the quality of your answer and probably provide you with more votes. – Samuel De Rycke Aug 18 '15 at 9:07
1

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.

  • Thank you for your answer, but I need the functionality in downloading XLS reports too. – Shumon Saha Jan 21 '13 at 12:12
  • Thank you for your suggestion. However, if the comma isn't there on the report tab, it won't reflect in the downloaded XLS too. So no need of opening a new question. – Shumon Saha Jan 22 '13 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.