You need to sign in to do that
Don't have an account?
saurab
NumberToWordFieldUpdate trigger is not working well .. "And" is getting appended at end which is not required
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
Can you check below line update ?
Hope above information was helpful.
Please mark as Best Answer so that it can help others in the future.
Thanks,
Vinay Kumar
for example for number 561 we need to get five hundred and sixty one.
for number 100004 we need to get one lakh and four .
and so on......................
Please check above code.