45 users online (0 members and 45 guests)  


  Results 1 to 2 of 2
  1. #1
    J-Man's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Nov 2003
    Posts
    32

    Javascript - Convert int to char (1 -> "001")

    How do you convert and integer to a character that is left filled with zeros? For example, if I have the integer 1, I want to convert that to "001". Thanks in advance!!!

  2. #2
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732
    Hi there J-Man,

    Try this....
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <meta name="generator"
        content="HTML Tidy for Linux/x86 (vers 1st November 2002), see www.w3.org" />
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
        <meta content="mshtml 6.00.2800.1264" name="generator" />
        <title>interger conversion</title>
        <style type="text/css">
        /*<![CDATA[*/
    body{font-family:arial;font-size:13px;font-weight:bold;}
    input{position:absolute;left:125px;width:100px;border:solid 2px  #000000;}
        /*]]>*/
        </style>
        <script type="text/javascript">
        //<![CDATA[
    function show_result()
    {
    var interger=document.getElementById("interger").value;
    var decimal='000'+interger;
    document.getElementById("result").value=decimal;
    }
       //]]>
        </script>
      </head>
      <body>
        <form action="">
          Put interger here:<input id="interger" type="text" /><br />
          <br />
          Conversion:<input id="result" type="text" /><br />
          <br />
          <input id="convert" type="button" value="convert" onclick="show_result();return false;" />
        </form>
      </body>
    </html>
    cthead



Tags for this Thread