Discussions
- General Development
- Schema Development
- Apex Code Development
- Visualforce Development
- Formulas & Validation Rules
- Security
- Mobile
- Force.com Sites & Site.com
- Chatter Development
- Java Development
- .NET Development
- Perl, PHP, Python & Ruby
- Desktop Integration
- APIs and Integrations
- Visual Workflow
- Apple, Mac and OS X
- VB and Office Development
- AppExchange Directory & Packaging
- Salesforce Labs & Open Source Projects
- Other Salesforce Applications
- Jobs Board
- Force.com Discussion Boards
- :
- Developer Boards for Force.com and Database.com
- :
- Apex Code Development
- :
- String.format is useless...
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
String.for mat is useless...
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-24-2013 05:50 AM
There's format in the String.method, however it's useless.
So that if want to add leading zero to a String in Apex controller, it must use a loop to add the leading zeros.
=== apex code ===
public class numberFormat {
Integer i = 1234;
String[] fmt1 = new String[]{'0, Number, $000000.00'};
String[] fmt2 = new String[]{'0', 'Number', '$000000.00'};
String[] fmt3 = new String[]{};
public String getNum1() {
return String.format(i.format(),fmt1);
}
public String getNum2() {
return String.format(i.format(),fmt2);
}
public String getNum3() {
return String.format(i.format(),fmt3);
}
public Integer getNum4() {
return i;
}
public Integer getNum5() {
return i;
}
}
=== Visualforce Page ===
<apex:page controller="numberFormat">
<apex:outputText value="{!num1}"/><br/>
<apex:outputText value="{!num2}"/><br/>
<apex:outputText value="{!num3}"/><br/>
<apex:outputText value="{!num4}"/><br/>
<apex:outputText value="{0, Number, $000000.00}">
<apex:param value="{!num5}" />
</apex:outputText>
</apex:page>
=== The output ===
1,234
1,234
1,234
1234
$001234.00
Solved! Go to Solution.
Re: String.for mat is useless...
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
01-24-2013 06:25 AM

