Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Tuesday, 23 December 2014

Calculate Amount In Words

function CalculateAmountInWords_ER() {
            var txtAmount_ER = document.getElementById('<%=txtAmount_ER.ClientID%>');
            var txtAmountInWords_ER = document.getElementById('<%=txtAmountInWords_ER.ClientID%>');

            var Round_Amount = Math.round(txtAmount_ER.value * 100) / 100;
            if (trim(txtAmount_ER.value, " ") != "") {
                txtAmount_ER.value = Round_Amount.toFixed(2);
                ConvertToWords(Math.round(txtAmount_ER.value), txtAmount_ER.id, txtAmountInWords_ER.id);
            }
            else {
                txtAmount_ER.value = "";
                txtAmountInWords_ER.value = "";
            }
        }

 function ConvertToWords(s, ClientID_Number, ClientID_words) {
            var num = s;
            num = Math.floor(s);
            var obStr = new String(num);
            numReversed = obStr.split("");
            actnumber = numReversed.reverse();

            if (Number(num) >= 0) {
                //do nothing
            }
          
            else {
                alert('Please enter a valid number!');
                if (ClientID_Number != "") {
                    document.getElementById(ClientID_Number).value = "";
                }
                if (ClientID_words != "") {
                    document.getElementById(ClientID_words).value = "";
                }
                return false;
            }
            if (Number(num) == 0) {
                document.getElementById(ClientID_Number).value = "";
                document.getElementById(ClientID_words).value = "";
                return false;
            }
            if (actnumber.length > 9) {
                alert('the Number is too big to covertes');
                return false;
            }

            var iWords = ["Zero", " One", " Two", " Three", " Four", " Five", " Six", " Seven", " Eight", " Nine"];
            var ePlace = ['Ten', ' Eleven', ' Twelve', ' Thirteen', ' Fourteen', ' Fifteen', ' Sixteen', ' Seventeen', ' Eighteen', ' Nineteen'];
            var tensPlace = ['dummy', ' Ten', ' Twenty', ' Thirty', ' Forty', ' Fifty', ' Sixty', ' Seventy', ' Eighty', ' Ninety'];

            var iWordsLength = numReversed.length;
            var totalWords = "";
            var inWords = new Array();
            var finalWord = "";
            j = 0;
            for (i = 0; i < iWordsLength; i++) {
                switch (i) {
                    case 0:
                        if (actnumber[i] == 0 || actnumber[i + 1] == 1) {
                            inWords[j] = '';
                        }
                        else {
                            inWords[j] = iWords[actnumber[i]];
                        }
                        inWords[j] = inWords[j] + ' Only';
                        break;
                    case 1:
                        tens_complication(ClientID_words);
                        break;
                    case 2:
                        if (actnumber[i] == 0) {
                            inWords[j] = '';
                        }
                        else if (actnumber[i - 1] != 0 && actnumber[i - 2] != 0) {
                            inWords[j] = iWords[actnumber[i]] + ' Hundred and';
                        }
                        else {
                            inWords[j] = iWords[actnumber[i]] + ' Hundred';
                        }
                        break;
                    case 3:
                        if (actnumber[i] == 0 || actnumber[i + 1] == 1) {
                            inWords[j] = '';
                        }
                        else {
                            inWords[j] = iWords[actnumber[i]];
                        }
                        if (actnumber[i + 1] != 0 || actnumber[i] > 0) {
                            inWords[j] = inWords[j] + " Thousand";
                        }
                        break;
                    case 4:
                        tens_complication(ClientID_words);
                        break;
                    case 5:
                        if (actnumber[i] == 0 || actnumber[i + 1] == 1) {
                            inWords[j] = '';
                        }
                        else {
                            inWords[j] = iWords[actnumber[i]];
                        }
                        if (iWordsLength <= 7) {
                            inWords[j] = inWords[j] + " Lakh";
                        }
                        else {
                            if (actnumber[i] == 0 && actnumber[i + 1] != 0) {
                                inWords[j] = inWords[j] + " Lakh";
                            }
                            if (actnumber[i] != 0 && actnumber[i + 1] == 0) {
                                inWords[j] = inWords[j] + " Lakh";
                            }
                        }                      
                        break;
                    case 6:
                        tens_complication(ClientID_words);
                        break;
                    case 7:
                        if (actnumber[i] == 0 || actnumber[i + 1] == 1) {
                            inWords[j] = '';
                        }
                        else {
                            inWords[j] = iWords[actnumber[i]];
                        }
                        inWords[j] = inWords[j] + " Crore";
                        break;
                    case 8:
                        tens_complication(ClientID_words);
                        break;
                    default:
                        break;
                }
                j++;
            }

No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.