• saurab
• NEWBIE
• 0 Points
• Member since 2017

• Chatter
Feed
• 0
• 0
• 0
Likes Given
• 1
Questions
• 1
Replies
```TRIGGER ----

trigger NumberToWordFieldUpdate on Invoice__c (before insert, before update) {
for (Invoice__c sc : Trigger.new) {
if (sc.Total_GST_value_Rs__c != null && sc.Total_GST_value_Rs__c >= 0) {
integer i = integer.valueOf(sc.Total_GST_value_Rs__c);
NumberToWord ntw = new NumberToWord();
sc.Total_GST_value_words__c = ntw.convert(i);
} else {
sc.Total_GST_value_words__c = null;
}
}
}

CLASS

public class NumberToWord {
public string wordText{set;get;}
public string convert() {
wordText=convert(numberval);
return null;
}
public long numberval { get; set; }
public String[] units = new String[]{' Zero ',' One ',' Two ',' Three ',' Four ',' Five ',' Six ',' Seven ',' Eight ',' Nine ',' Ten ','Eleven ','Twelve ','Thirteen ','Fourteen ','Fifteen ','Sixteen ','Seventeen ','Eighteen ','Nineteen '};
public String[] tens = new String[]{'','','Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety'};
public  String convert(long i) {
if( i < 20)  return units[integer.valueOf(i)];
if( i < 100) return tens[integer.valueOf(i)/10] + ((math.mod(i , 10) > 0)? '' + convert(math.mod(i , 10)):'');
if( i < 1000) return units[integer.valueOf(i)/100] + ' Hundred and' + ((math.mod(i , 100) > 0)?' ' + convert(math.mod(i , 100)):'');
if( i < 10000) return units[integer.valueOf(i)/1000] + ' Thousand ' + ((math.mod(i , 1000) > 0)?' ' + convert(math.mod(i , 1000)):'');
if( i < 100000) return convert(i / 1000) + ' Thousand ' + ((math.mod(i , 1000) > 0)? '' + convert(math.mod(i ,1000)):'') ;
if( i < 1000000) return units[integer.valueOf(i)/100000] + ' Lakh ' + ((math.mod(i , 100000) > 0)? '' + convert(math.mod(i ,100000)):'') ;
if( i < 10000000) return convert(i / 100000) + ' Lakh ' + ((math.mod(i , 100000) > 0)? '' + convert(math.mod(i ,100000)):'') ;
if( i < 100000000) return units[integer.valueOf(i)/10000000] + ' Crore ' + ((math.mod(i , 10000000) > 0)? '' + convert(math.mod(i , 10000000)):'') ;
if( i < 1000000000) return convert(i / 10000000) + 'Crore ' + ((math.mod(i , 10000000) > 0)? '' + convert(math.mod(i , 10000000)):'') ;
return 'Sorry, Too Big';
}
}

input  104400

expected op    One Lakh Four Thousand and Four Hundred

output One Lakh Four Thousand Four Hundred and```

```TRIGGER ----

trigger NumberToWordFieldUpdate on Invoice__c (before insert, before update) {
for (Invoice__c sc : Trigger.new) {
if (sc.Total_GST_value_Rs__c != null && sc.Total_GST_value_Rs__c >= 0) {
integer i = integer.valueOf(sc.Total_GST_value_Rs__c);
NumberToWord ntw = new NumberToWord();
sc.Total_GST_value_words__c = ntw.convert(i);
} else {
sc.Total_GST_value_words__c = null;
}
}
}

CLASS

public class NumberToWord {
public string wordText{set;get;}
public string convert() {
wordText=convert(numberval);
return null;
}
public long numberval { get; set; }
public String[] units = new String[]{' Zero ',' One ',' Two ',' Three ',' Four ',' Five ',' Six ',' Seven ',' Eight ',' Nine ',' Ten ','Eleven ','Twelve ','Thirteen ','Fourteen ','Fifteen ','Sixteen ','Seventeen ','Eighteen ','Nineteen '};
public String[] tens = new String[]{'','','Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety'};
public  String convert(long i) {
if( i < 20)  return units[integer.valueOf(i)];
if( i < 100) return tens[integer.valueOf(i)/10] + ((math.mod(i , 10) > 0)? '' + convert(math.mod(i , 10)):'');
if( i < 1000) return units[integer.valueOf(i)/100] + ' Hundred and' + ((math.mod(i , 100) > 0)?' ' + convert(math.mod(i , 100)):'');
if( i < 10000) return units[integer.valueOf(i)/1000] + ' Thousand ' + ((math.mod(i , 1000) > 0)?' ' + convert(math.mod(i , 1000)):'');
if( i < 100000) return convert(i / 1000) + ' Thousand ' + ((math.mod(i , 1000) > 0)? '' + convert(math.mod(i ,1000)):'') ;
if( i < 1000000) return units[integer.valueOf(i)/100000] + ' Lakh ' + ((math.mod(i , 100000) > 0)? '' + convert(math.mod(i ,100000)):'') ;
if( i < 10000000) return convert(i / 100000) + ' Lakh ' + ((math.mod(i , 100000) > 0)? '' + convert(math.mod(i ,100000)):'') ;
if( i < 100000000) return units[integer.valueOf(i)/10000000] + ' Crore ' + ((math.mod(i , 10000000) > 0)? '' + convert(math.mod(i , 10000000)):'') ;
if( i < 1000000000) return convert(i / 10000000) + 'Crore ' + ((math.mod(i , 10000000) > 0)? '' + convert(math.mod(i , 10000000)):'') ;
return 'Sorry, Too Big';
}
}

input  104400

expected op    One Lakh Four Thousand and Four Hundred

output One Lakh Four Thousand Four Hundred and```