Saturday 14 June 2014

Convert Currencey to Words:

Convert Rupees to words in Apex.




Visualforce Page:

<apex:page controller="Currenceyconverter" docType="html-5.0">
<apex:form >
<apex:pageBlock title="Convert Currencey to Words">
<apex:pageBlockButtons location="bottom">
     <apex:commandButton action="{!getdata}" value="submit" reRender="outputtext"/>
</apex:pageBlockButtons>
<apex:pageBlockSection columns="3">
    <apex:outputLabel >Enter Currencey to convert:</apex:outputLabel>
    <apex:input type="number" value="{!textval}"/>
    <apex:outputLabel ></apex:outputLabel>
</apex:pageBlockSection>
    <apex:outputText value="{!wordtext}" id="outputtext" style="color:green;font-size:15px;font-weight: bold;margin-left: 240px;"></apex:outputText>
</apex:pageBlock>

 </apex:form>
</apex:page>

Apex Class:


public class Currenceyconverter {

    public String wordtext { get; set; }
    public integer textval{get;set;}
    public void getdata() {
    wordtext=convert(textval);
    system.debug('mahi :'+wordtext);
        
    }

    private static String[] units=new String[]{'',' One',' Two',' Three',' Four',' Five',' Six',' Seven',' Eight',' Nine'};
    private static String[] teen=new String[]{' Ten',' Eleven',' Twelve',' Thirteen',' Fourteen',' Fifteen',' Sixteen',' Seventeen',' Eighteen',' Nineteen'};
    private static String[] tens=new String[]{' Twenty',' Thirty',' Fourty',' Fifty',' Sixty',' Seventy',' Eighty',' Ninety'};
    private static String[] maxs=new String[]{'','',' Hundred',' Thousand',' Lakh',' Crore'};
    public string digitsToWord(string val){
        String Convertedtext='';
        list<string> Vallist=val.split('');
                string sss=Vallist.remove(0);
        for(integer i=Vallist.size()-1;i>=0;i--){
            integer index=integer.valueof(Vallist[i]);
            if(i==0&&index>1&&Vallist.size()>1)
                 Convertedtext=tens[index-2]+Convertedtext;
            else if(i==0&&index==1&&Vallist.size()==2){
                integer sum=0;
                for(integer j=0;j<2;j++){
                     sum=(sum*10)+integer.valueof(Vallist[j]);
                } 
                return teen[sum-10];  
            }
            else{
                
                 if(index>0)
                     Convertedtext=units[index]+Convertedtext;
            }
        }
        return Convertedtext;
    }
    
   public String convert(integer n) {
       if(n==0)
           return 'Zero';
        if(n>999999999)
            return 'More then 100 corers ';
       string amount=string.valueOf(n);
       integer positioning=1;
       boolean IsHundred=false;
       string Convertedtext='';
       while(amount.length()>0){
           if(positioning==1){
               if(amount.length()>=2){
                   String C=amount.substring(amount.length()-2,amount.length());
                   amount=amount.substring(0,amount.length()-2); 
                   Convertedtext+=digitsToWord(C); 
               } else if(amount.length()==1){
                    Convertedtext+=digitsToWord(amount);
                    amount=''; 
               }positioning++;
           }
           else if(positioning==2){
               String C=amount.substring(amount.length()-1,amount.length());
               amount=amount.substring(0,amount.length()-1);
               if(Convertedtext.length()>0&&digitsToWord(C)!=''){ 
                   Convertedtext=(digitsToWord(C)+maxs[positioning]+' and')+Convertedtext;
                   IsHundred=true; 
               }
               else{ 
                   if(digitsToWord(C)!='')
                     Convertedtext=(digitsToWord(C)+maxs[positioning])+Convertedtext;IsHundred=true;
               }
               positioning++;
           }
           else if(positioning>2){
               if(amount.length()>=2){
                   String C=amount.substring(amount.length()-2,amount.length()); amount=amount.substring(0,amount.length()-2);
                   if(!IsHundred&&Convertedtext.length()>0)
                       Convertedtext=digitsToWord(C)+maxs[positioning]+' and'+Convertedtext;
                   else{ if(digitsToWord(C)=='') {} else Convertedtext=digitsToWord(C)+maxs[positioning]+Convertedtext; }
               } else if(amount.length()==1){
                   if(!IsHundred&&Convertedtext.length()>0)
                       Convertedtext=digitsToWord(amount)+maxs[positioning]+' and'+Convertedtext;  
                   else{ if(digitsToWord(amount)==''){}else Convertedtext=digitsToWord(amount)+maxs[positioning]+Convertedtext;   amount='';  } 
                   
               }
                positioning++;
           }
        }
       
   return Convertedtext;
   }

}

Tuesday 21 January 2014

Quick Login to Salesforce:
                           Now users can login to your Org with single Step.we don`t need to spend more time on login.
Production/Dev URL: https://login.salesforce.com/?un=Username&pw=Password
Sandbox URL: https://test.salesforce.com/?un=Username&pw=Password

    Links