Reply
Regular Contributor
Superdome-old
Posts: 14
0
Accepted Solution

String.format is useless...

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   

Regular Contributor
Superdome-old
Posts: 14
0

Re: String.format is useless...

Want to add leading zeros, try the code here:

 

http://mauricekremer.dyndns.org/?p=92