1,105,447 Community Members

convert indian amount to words with rupees and paise

Member Avatar
biswa2ray
Newbie Poster
17 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

hai all,

i want to convert indian rupees into words, is there any function in javascript or any useful links
are appreciated..

how to convert indian rupees to words

for ex
234.45=Two hundred thirty four rupees and fourty five paise only.

this want for any number upto billions..

Member Avatar
Bachov Varghese
Posting Whiz in Training
205 posts since Sep 2011
Reputation Points: 45 [?]
Q&As Helped to Solve: 52 [?]
Skill Endorsements: 6 [?]
 
0
 
Member Avatar
radhakrishna.p
Posting Whiz in Training
281 posts since Nov 2012
Reputation Points: 29 [?]
Q&As Helped to Solve: 64 [?]
Skill Endorsements: 11 [?]
 
0
 

have you done anything so far ?

if pls post here so taht we are here to help you

Member Avatar
biswa2ray
Newbie Poster
17 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

@radhakrishna my page code is .....

<%@ page import="java.sql.*"%>
<%@ page import="java.util.Date"%>
<%@ page import="java.text.*"%>
<%!int val;
 String slno;
 Connection con;
 Statement st;

 %>
 <%
 try
 {
 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
 con=DriverManager.getConnection("jdbc:odbc:k","hindustan","hindustan");
 st=con.createStatement();
 ResultSet rs=st.executeQuery("select count(*) from voucher where type='Payment'");

    while (rs.next())
    {
    val=rs.getInt(1);
    }
    val=val+1;
    slno="PMT"+val;
 }
 catch(Exception e)
 {
    e.printStackTrace();
 }
 %>

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<script language="javaScript" type="text/javascript" src="calendar.js"></script>

   <link href="calendar.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Receipt voucher</title>
<script language ="javascript">

function showMe(id) 
{ 

var obj = document.getElementById(id);

    obj.style.visibility = "visible";
    document.rv.cd.value="";
    document.rv.bn.value="";
    document.rv.cn.value="";
    document.rv.ba.value="";
    document.rv.ac.value="";
    document.rv.ach.value="";


}

function showMe1(id) 
{ 

var obj = document.getElementById(id);

    obj.style.visibility = "hidden";
    document.rv.cd.value="NIL";
    document.rv.cn.value="NIL";
    document.rv.bn.value="NIL";
    document.rv.ba.value="NIL";
    document.rv.ac.value="NIL";
    document.rv.ach.value="NIL";

}



function chqvalidate()

{
    if (document.rv.cd.value=="")
    {
        alert("Enter Cheque Date(dd/mm/yyyy)");

        document.rv.cd.select();
        document.rv.cd.focus();
    }
    else if (document.rv.cn.value=="")
    {
        alert("Enter Cheque No");
        document.rv.cn.select();
        document.rv.cn.focus();
    }

    else if (document.rv.bn.value=="")
    {
        alert("Enter Bank Name");
        document.rv.bn.select();
        document.rv.bn.focus();
    }
    else if (document.rv.ba.value=="")
    {
        alert("Enter Bank Address");
        document.rv.ba.select();
        document.rv.ba.focus();
    }
    else if (document.rv.ac.value=="")
    {
        alert("Enter A/C No");
        document.rv.ac.select();
        document.rv.ac.focus();
    }
    else if(document.rv.ach.value=="")
    {
        alert("Enter A/C Holder Name");
        document.rv.ach.select();
        document.rv.ach.focus();
    }
}

function callme1()

{

    if(document.rv.action1[0].checked==true)
    {
    var action1=document.rv.action1[0].value;
    //Landlord
    document.rv.action1[0].checked=true;
    rv.action="paymentvoucher.jsp?action1="+action1;
    rv.submit();

    }

    else if(document.rv.action1[1].checked==true)
    {
    var action1=document.rv.action1[1].value;
    //Agency
    document.rv.action1[1].checked=true;
    rv.action="paymentvoucher.jsp?action1="+action1;
    rv.submit();

    }
    else
    {
    var action1=document.rv.action1[2].value;
    //Customer
    document.rv.action1[2].checked=true;
    rv.action="paymentvoucher.jsp?action1="+action1;
    rv.submit();

    }
}
function setstatus()

{
    var dd=document.rv.ddd.value;

    if(dd=="Landlord")
    {
    document.rv.action1[0].checked=true;    
    }
    else if(dd=="Agency")
    {
        document.rv.action1[1].checked=true;

    }
    else
    {
        document.rv.action1[2].checked=true;

    }
}

function callme2()

{
    var mainval=document.rv.D1.value;

    var mainval1=mainval.split("--");
    var mainval2=mainval1[0];

    document.rv.T4.value=mainval2;
    document.rv.T3.value=mainval1[1];
}


//Division Visible/Invisible


function callme()
    {
         if (document.rv.datum2.value=="")    
    {
    alert("Voucher Date can not Null"); 
    document.rv.datum2.select;
    document.rv.datum2.focus;

    }
     else if (document.rv.T3.value=="")   
    {
    alert("Party Code can not be Null");
    document.rv.T3.focus();
    }
     else if (document.rv.T4.value=="")   
    {
    alert("Party Name can not be Null");
    document.rv.T4.focus();
    }
    else if (document.rv.T5.value=="")   
    {
    alert("Plese Enter Amount");
    document.rv.T5.focus();
    }
else
        {
    rv.action="PaymentVoucher";
    rv.submit();
        }
    }
</script>

</head>

<body style="background-image:url('pic/beach-red-sepia-design.jpg')" onload="setstatus()">
<form name="rv" method="post" >

<div align="center">
    <table border="1" width="62%" bgcolor="#33CCFF" id="table1">
        <tr>
            <td colspan="4">
            <p align="center"><b><font size="6" face="AR CENA">Payment Voucher</font></b></td>
        </tr>
        <tr>
            <td width="20%"><b>Voucher No</b></td>
            <td width="22%"><b><input type="text" name="T1" size="12" style="background-color:yellow ;font-family:Arial Black; font-size: 10pt; color: #800000" size="12" align=center value="<%=slno%>" readonly ></b></td>
            <td width="16%"><b>Voucher Date</b></td>

    <%!Date d=null;
       String Display=null;
    %>
            <%
                d=new Date();
    int month=d.getMonth()+1;
    int day= d.getDate();
    int year=d.getYear()+1900;

    //SimpleDateFormat pd=new SimpleDateFormat("mmm/dd/yyyy");
    Display=day+"-"+month+"-"+year;

    %>
            <td width="37%"><input type="text" name="datum2" value="<%=Display%>" size="13" title="Select Date from Picker" readonly>
            <a href ="#" onClick="setYears(2000, 2020); showCalender(this, 'datum2');"><img src="calender.png"></a>
            </td>
        </tr>
        <tr>

<%

String action1=request.getParameter("action1");
if(action1==null||action1.equals(""))
{
action1="Landlord";
}
else if(action1==null||action1.equals(""))
{
action1="Customer";
}
else
{
    action1=request.getParameter("action1");

}

%>

        <input type="hidden" name="ddd" value="<%=action1%>">
            <td width="20%"><b>Type</b></td>
            <td width="76%" colspan="3">
            <input type="radio" value="Landlord" name="action1" onclick="callme1()">Landlord
            <input type="radio" value="Agency" name="action1" onclick="callme1()">Agency
            <input type="radio" value="Customer" name="action1" onclick="callme1()">Customer
             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <select size="1" name="D1" onchange="callme2()"><option>Select</option>

<%
if(action1.equals("Customer"))
{
String query1="select cust_id,comp_name from customer order by comp_name" ;
System.out.println(query1+";;;;;;;;;;;;;;");
ResultSet rs1=st.executeQuery(query1);
while(rs1.next())
{
    String code=rs1.getString(1);
    String name1=rs1.getString(2);


    String mainval=name1+"--"+code;
    %>
<option value=<%=mainval%>><%=mainval%></option>
<%
}
    }
    else
    {
String query1="select cr_code,name1  from creditor where type='"+action1+"' order by name1" ;
System.out.println(query1+";;;;;;;;;;;;;;");
ResultSet rs1=st.executeQuery(query1);
while(rs1.next())
{
    String code=rs1.getString(1);
    String name1=rs1.getString(2);


    String mainval=name1+"--"+code;
    %>
<option value=<%=mainval%>><%=mainval%></option>
<%
}
    }

%>

        </select></td>
        </tr>
        <tr>
            <td width="20%"><b>Party Code</b></td>
            <td width="22%"><input type="text" name="T3" size="12" style="background-color:#CCCCCC ;font-family:Comic Sans MS; font-size: 10pt; color: #000080" readonly></td>
            <td width="16%"><b>Party Name</b></td>
            <td width="37%">
            <input type="text" name="T4" size="29" style="background-color:#CCCCCC ;font-family:Comic Sans MS; font-size: 10pt; color: #000080" readonly></td>
        </tr>

        <tr>
            <td width="20%"><b>Mode of Payment</b></td>
            <td width="76%" colspan="3">
            <input type="radio" name="R1" value="Cash" onclick=showMe1('div1') >Cash
            <input type="radio" name="R1" value="Cheque" onclick=showMe('div1') checked>Cheque<div id="div1">
                <table border="0" width="101%" id="table1">
    <tr>
        <td colspan="4" bgcolor="#FFFF66">
        <p align="center"><font face="Bradley Hand ITC" color="#808000"><b>
        Cheque Details</b></font></td>
    </tr>
    <tr>
        <td width="15%"><font face="Goudy Old Style" size="2">Cheque</font><font face="Goudy Old Style" size="2"> 
        Date</font></td>
        <td width="22%"><input type="text" name="cd" size="11" title="Select Date from Picker" readonly><a href="#" onClick="setYears(1974, 2020);
       showCalender(this, 'cd');">
      <img src="calender.png"></a></td>
        <td width="21%"><font size="2" face="Goudy Old Style">Bank Name</font></td>
        <td width="38%"><input type="text" name="bn" size="25"></td>
    </tr>
    <tr>
        <td width="15%" height="24"><font face="Goudy Old Style" size="2">Cheque</font><font face="Goudy Old Style" size="2"> 
        No</font></td>
        <td height="24" width="22%"><input type="text" name="cn" size="13"></td>
        <td height="24" width="21%"><font size="2" face="Goudy Old Style">Bank 
        Address</font></td>
        <td width="38%" height="24"><input type="text" name="ba" size="25"></td>
    </tr>
    <tr>
        <td width="15%"><font size="2" face="Goudy Old Style">A/C No.</font></td>
        <td width="22%"><input type="text" name="ac" size="14"></td>
        <td width="21%"><font size="2" face="Goudy Old Style">A/C Holder Name</font></td>
        <td width="38%"><input type="text" name="ach" size="25"></td>
    </tr>

</table></div></td>
        </tr>
        <tr>
            <td width="20%"><b>Amount</b></td>
            <td width="76%" colspan="3"><input type="text" name="T5" size="12" onclick="chqvalidate()"></td>
        </tr>
        <tr>
            <td width="20%"><b><i>Amount in words</i></b></td>
            <td width="76%" colspan="3"><input type="text" name="T6" size="67"></td>
        </tr>
        <tr>
            <td width="97%" colspan="4">
            <p align="center">
            <input type="submit" value="Save" name="B1" style="width: 60; font-size: 12pt; font-family: Zurich Lt BT; color: #008000; text-decoration: blink; font-style: italic; height: 25" onclick="callme()" >
            <input type="reset" value="Reset" name="B2"></td>
        </tr>
    </table>
</div>
</form>
</center>
<!-- Calender Script  --> 

    <table id="calenderTable">
        <tbody id="calenderTableHead">
          <tr>
            <td colspan="4" align="center">
              <select onChange="showCalenderBody(createCalender(document.getElementById('selectYear').value,
               this.selectedIndex, false));" id="selectMonth">
                  <option value="0">Jan</option>
                  <option value="1">Feb</option>
                  <option value="2">Mar</option>
                  <option value="3">Apr</option>
                  <option value="4">May</option>
                  <option value="5">Jun</option>
                  <option value="6">Jul</option>
                  <option value="7">Aug</option>
                  <option value="8">Sep</option>
                  <option value="9">Oct</option>
                  <option value="10">Nov</option>
                  <option value="11">Dec</option>
              </select>
            </td>
            <td colspan="2" align="center">
                <select onChange="showCalenderBody(createCalender(this.value, 
                document.getElementById('selectMonth').selectedIndex, false));" id="selectYear">
                </select>
            </td>
            <td align="center">
                <a href="#" onClick="closeCalender();"><font color="#003333" size="+1">X</font></a>
            </td>
          </tr>
       </tbody>
       <tbody id="calenderTableDays">
         <tr style="">
           <td>Sun</td><td>Mon</td><td>Tue</td><td>Wed</td><td>Thu</td><td>Fri</td><td>Sat</td>
         </tr>
       </tbody>
       <tbody id="calender"></tbody>
    </table>

<!-- End Calender Script  -->
</body>

</html>
Member Avatar
biswa2ray
Newbie Poster
17 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

@radhakrishna my modify page code is .....
plz help me...

<%@ page import="java.sql.*"%>
<%@ page import="java.text.*"%>
<%!int val;
 String slno;
 Connection con;
 Statement st;

 %>


<html>

<head>   
<title>Receipt voucher</title>
<script language ="javascript">


</script>

</head>

<body style="background-image:url('pic/beach-red-sepia-design.jpg')" onload="setstatus()">
<form name="rv" method="post" >

<div align="center">
    <table border="1" width="62%" bgcolor="#33CCFF" id="table1">
        <tr>
            <td colspan="4">
            <p align="center"><b><font size="6" face="AR CENA">Payment Voucher</font></b></td>
        </tr>
        <tr>
            <td width="20%"><b>Party Code</b></td>
            <td width="22%"><input type="text" name="mod" size="12" style="background-color:#CCCCCC ;font-family:Comic Sans MS; font-size: 10pt; color: #000080" ></td>
            <td width="16%"><b>Party Name</b></td>
            <td width="37%">
            <input type="text" name="T4" size="29" style="background-color:#CCCCCC ;font-family:Comic Sans MS; font-size: 10pt; color: #000080"></td>
        </tr>

        <tr>
            <td width="20%"><b>Mode of Payment</b></td>
            <td width="76%" colspan="3">
            <div id="div1">
                <input type="text" name="T7" size="12" onclick="chqvalidate()"></div></td>
        </tr>
        <tr>
            <td width="20%"><b>Amount</b></td>
            <td width="76%" colspan="3"><input type="text" name="T5" size="12" onclick="chqvalidate()"></td>
        </tr>
        <tr>
            <td width="20%"><b><i>Amount in words</i></b></td>
            <td width="76%" colspan="3"><input type="text" name="T6" size="67"></td>
        </tr>
        <tr>
            <td width="97%" colspan="4">
            <p align="center">
            <input type="submit" value="Save" name="B1" style="width: 60; font-size: 12pt; font-family: Zurich Lt BT; color: #008000; text-decoration: blink; font-style: italic; height: 25" onclick="callme()" >
            <input type="reset" value="Reset" name="B2"></td>
        </tr>
    </table>
</div>
</form>
</center>
</body>

</html>
Member Avatar
radhakrishna.p
Posting Whiz in Training
281 posts since Nov 2012
Reputation Points: 29 [?]
Q&As Helped to Solve: 64 [?]
Skill Endorsements: 11 [?]
 
0
 
Member Avatar
biswa2ray
Newbie Poster
17 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

@ radhakrishna! Not working in my page...Will you suggest me.How my page code will be..

Member Avatar
radhakrishna.p
Posting Whiz in Training
281 posts since Nov 2012
Reputation Points: 29 [?]
Q&As Helped to Solve: 64 [?]
Skill Endorsements: 11 [?]
 
1
 

i used the same script by doing one example

here is that example and its work great

<html>
<head>
<title>welcome to Convert Currency In Words(http://pandiyachendur.blogspot.in/2009/11/javascript-to-convert-indian-

rupees-in.html)</title>


<script type="text/javascript">


function test_value() {
    var junkVal=document.getElementById('rupees').value;
    junkVal  = Math.floor(junkVal);
    var obStr = new String(junkVal);
    numReversed= obStr.split("");
    actnumber=numReversed.reverse();

    if(Number(junkVal) >=0){
        //do nothing
    }
    else{
        alert('wrong Number cannot be converted');
        return false;
    }
    if(Number(junkVal)==0){
        document.getElementById('container').innerHTML=obStr+''+'Rupees Zero Only';
        return false;
    }
    if(actnumber.length>9){
        alert('Oops!!!! 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];
            break;
        case 1:
            tens_complication();
            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();
            break;
        case 5:
            if(actnumber[i]==0 || actnumber[i+1]==1 ) {
                inWords[j]='';
            }
            else {
                inWords[j]=iWords[actnumber[i]];
            }
            inWords[j]=inWords[j]+" Lakh";
            break;
        case 6:
            tens_complication();
            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();
            break;
        default:
            break;
        }
        j++;
    }

    function tens_complication() {
        if(actnumber[i]==0) {
            inWords[j]='';
        }
        else if(actnumber[i]==1) {
            inWords[j]=ePlace[actnumber[i-1]];
        }
        else {
            inWords[j]=tensPlace[actnumber[i]];
        }
    }
    inWords.reverse();
    for(i=0; i<inWords.length; i++) {
        finalWord+=inWords[i];
    }
        return finalWord;
}

function convert_amount_into_rupees_paisa(){
        var finalWord1 = test_value();
        var finalWord2 = "";

        var val = document.getElementById('rupees').value;
        var actual_val  = document.getElementById('rupees').value; 
        document.getElementById('rupees').value = val;

        if(val.indexOf('.')!=-1)
       {
              val = val.substring(val.indexOf('.')+1,val.length);
              if(val.length==0 || val.length=='00'){
                 finalWord2 = "zero paisa only";
              }
              else{
               document.getElementById('rupees').value = val;
               finalWord2 = test_value() + " paisa only";
              }
             document.getElementById('container').innerHTML=finalWord1 +" Rupees and "+finalWord2;
       }
       else{
             //finalWord2 =  " Zero paisa only";
             document.getElementById('container').innerHTML=finalWord1 +" Rupees Only";
       }
    document.getElementById('rupees').value = actual_val;   
}
</script>
<head>
<body>

Enter Amount :<input type="text" name="rupees" value="" id="rupees" /> <br/>
Amount in Words : <br>
<div id="container" style="height:50px;width:500px;background-color: lightgreen">
.................................
</div>

<input type="button" name="button1" value="Get In Words"  onclick="convert_amount_into_rupees_paisa() " /><br/>

</body>
</html>

check it once and change the code accordingly as your requirement

(what i mean is filed name of the amount, where to display the amount in words and calling the javascript method in your code)

thats it

Note: not tested for all the possible user inputs but its giving your actual output upto some extent

Member Avatar
biswa2ray
Newbie Poster
17 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

@ radhakrishna! I was testing this code in EditPlus. Showing Error message "Unterminated string constand on Line-31, char-124. and it is not converting...

Member Avatar
radhakrishna.p
Posting Whiz in Training
281 posts since Nov 2012
Reputation Points: 29 [?]
Q&As Helped to Solve: 64 [?]
Skill Endorsements: 11 [?]
 
0
 

please replace following code in your script code what we had so far (in the given example ).

i just made some changes to this method

function convert_amount_into_rupees_paisa(){
        var finalWord1 = test_value();
        var finalWord2 = "";

        var val = document.getElementById('rupees').value;
        var actual_val  = document.getElementById('rupees').value; 
        document.getElementById('rupees').value = val;

        if(val.indexOf('.')!=-1)
       {
              val = val.substring(val.indexOf('.')+1,val.length);
              if(val.length==0){
    finalWord2 = "";
    document.getElementById('container').innerHTML=finalWord1 +" Rupees Only"+finalWord2;
              }
              else{
                  document.getElementById('rupees').value = val;
                  if(val != '00'){                      
                      finalWord2 = test_value() + " paisa only";
                      document.getElementById('container').innerHTML=finalWord1 +" Rupees and "+finalWord2;
                  }else{           
                      finalWord2 = "";
                      document.getElementById('container').innerHTML=finalWord1 +" Rupees only"+finalWord2;
                  }
              }

       }
       else{
             //finalWord2 =  " Zero paisa only";
             document.getElementById('container').innerHTML=finalWord1 +" Rupees Only";
       }
    document.getElementById('rupees').value = actual_val;   
}

check it and let me know the status

Member Avatar
radhakrishna.p
Posting Whiz in Training
281 posts since Nov 2012
Reputation Points: 29 [?]
Q&As Helped to Solve: 64 [?]
Skill Endorsements: 11 [?]
 
0
 

i found that syntax error in my script code (what i have posted so far in this blog )

Syntax Error : reasons

keep this ePlace array values in a single line as follows (while posting this code into here the values are jumped to another line that gives the above syntax error )

var ePlace=['Ten',' Eleven', ' Twelve', ' Thirteen', ' Fourteen', ' Fifteen', ' Sixteen', ' Seventeen', ' Eighteen', 'Nineteen'];

so keep the array values in sigle line and test it

it works fine on my side

let me know the status

happy coding

Member Avatar
biswa2ray
Newbie Poster
17 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Not working... :(
Will you write the total page code for me.

Member Avatar
biswa2ray
Newbie Poster
17 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Many many thanks...radhakrishna.p .Now it working...

Member Avatar
Xitij
Newbie Poster
1 post since Oct 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi,
I'm looking for a script to display amount in words.
I found your blog & try it.
But found a bug in this script..
It display "One Crore Lakh Rupees Only" when enter "10000000" amount. It should be "One Crore Rupees Only".

Member Avatar
radhakrishna.p
Posting Whiz in Training
281 posts since Nov 2012
Reputation Points: 29 [?]
Q&As Helped to Solve: 64 [?]
Skill Endorsements: 11 [?]
 
0
 

hai Xitij,

great to here and nicely found the bug.thanks alot to you for that

just now i changed the code to fix that bug

here is the modified version of the code

<html>
<head>
<title>welcome to Convert Currency In Words(http://pandiyachendur.blogspot.in/2009/11/javascript-to-convert-indian-rupees-in.html)</title>

<script type="text/javascript">


function test_value() {
    var junkVal=document.getElementById('rupees').value;
    junkVal  = Math.floor(junkVal);
    var obStr = new String(junkVal);
    numReversed= obStr.split("");
    actnumber=numReversed.reverse();

    if(Number(junkVal) >=0){
        //do nothing
    }
    else{
        alert('wrong Number cannot be converted');
        return false;
    }
    if(Number(junkVal)==0){
        document.getElementById('container').innerHTML=obStr+''+'Rupees Zero Only';
        return false;
    }
    if(actnumber.length>9){
        alert('Oops!!!! 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];
            break;
        case 1:
            tens_complication();
            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){ //here
                inWords[j]=inWords[j]+" Thousand";
            }
            break;
        case 4:
            tens_complication();
            break;
        case 5:
            if(actnumber[i]=="0" || actnumber[i+1]==1 ) {
                inWords[j]='';
            }
            else {
                inWords[j]=iWords[actnumber[i]];
            }
            if(actnumber[i+1] != 0 || actnumber[i] > 0){   //here 
                inWords[j]=inWords[j]+" Lakh";
            }

            break;
        case 6:
            tens_complication();
            break;
        case 7:
            if(actnumber[i]=="0" || actnumber[i+1]==1 ){
                inWords[j]='';
            }
            else {
                inWords[j]=iWords[actnumber[i]];
            }
            if(actnumber[i+1] != 0 || actnumber[i] > 0){ // changed here
                inWords[j]=inWords[j]+" Crore";
            }
            break;
        case 8:
            tens_complication();
            break;
        default:
            break;
        }
        j++;
    }

    function tens_complication() {
        if(actnumber[i]==0) {
            inWords[j]='';
        }
        else if(actnumber[i]==1) {
            inWords[j]=ePlace[actnumber[i-1]];
        }
        else {
            inWords[j]=tensPlace[actnumber[i]];
        }
    }
    inWords.reverse();
    for(i=0; i<inWords.length; i++) {
        finalWord+=inWords[i];
    }
        return finalWord;
}

function convert_amount_into_rupees_paisa(){
        var finalWord1 = test_value();
        var finalWord2 = "";

        var val = document.getElementById('rupees').value;
        var actual_val  = document.getElementById('rupees').value; 
        document.getElementById('rupees').value = val;

        if(val.indexOf('.')!=-1)
       {
              val = val.substring(val.indexOf('.')+1,val.length);
              if(val.length==0 || val.length=='00'){
                 finalWord2 = "zero paisa only";
              }
              else{
               document.getElementById('rupees').value = val;
               finalWord2 = test_value() + " paisa only";
              }
             document.getElementById('container').innerHTML=finalWord1 +" Rupees and "+finalWord2;
       }
       else{
             //finalWord2 =  " Zero paisa only";
             document.getElementById('container').innerHTML=finalWord1 +" Rupees Only";
       }
    document.getElementById('rupees').value = actual_val;   
}
</script>
<head>
<body>

Enter Amount :<input type="text" name="rupees" value="" id="rupees" /> <br/>
Amount in Words : <br>
<div id="container" style="height:50px;width:500px;background-color: lightgreen">
.................................
</div>

<input type="button" name="button1" value="Get In Words"  onclick="convert_amount_into_rupees_paisa() " /><br/>

</body>
</html>

check it once and let me know

Member Avatar
shruthir25
Newbie Poster
1 post since Mar 2014
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

i want a code for converting indian amount to words with rupees and paise in core java

You
Post:
Start New Discussion
View similar articles that have also been tagged: