Tell me more ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I have a custom field who's type is number, with format: 18 digit, 0 decimal places. However, when I output it using <apex:outputfield value="soBject__c.Number__c" /> for example, it displays: 18.0 dispite the fact that it's 0 decimal places in the number?

Is there anyway to hide the .0 ? Or do I just need to convert it to a string?

share|improve this question

2 Answers

up vote 5 down vote accepted

I've found that by far the easiest/simplest way to achieve this is to just use the FLOOR() Visualforce function:

<apex:outputText value="{!FLOOR(sObject.Number__c)}"/>
share|improve this answer
This works great when the scale is 0 (your case). – DerekLansing Sep 12 '12 at 4:34
Yeah, you don't want to use it for situations where you want to keep your decimal part (or round correctly), but when scale is 0 and you don't want the .0 showing, it's the option with the cleanest markup IMO. – LaceySnr Sep 12 '12 at 4:38
I agree that this is much simpler than the MessageFormat, and therefore better IMO. This question only asks specifically about whole numbers with 0 decimal places which this method covers. – Peter Knolle Sep 12 '12 at 10:33

would formatting do the trick?

   <apex:outputText value="{0,number,#,##0}">$    
       <apex:param value="{!soBject__c.Number__c}"/>
    </apex:outputText>
share|improve this answer
That's what I do as well. For reference, the outputText supports the syntax of docs.oracle.com/javase/1.4.2/docs/api/java/text/…. You can look at the related Format classes (e.g., subclasses of docs.oracle.com/javase/1.4.2/docs/api/java/text/Format.html such as DecimalFormat) for the various format Strings. – Peter Knolle Sep 11 '12 at 23:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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