Results 1 to 8 of 8

Scientific Calculator

This is a discussion on Scientific Calculator within the Programming forums, part of the Web Designing & Development category; This is a very cool JavaScript calculator that does many advanced functions - cosine, sine, tangent, square root, exponents, etc. ...

  1. #1
    Senior Member Array akash's Avatar
    Join Date
    Oct 2008
    Location
    Heaven (Earth)
    Posts
    500

    Default Scientific Calculator

    This is a very cool JavaScript calculator that does many advanced functions - cosine, sine, tangent, square root, exponents, etc. Very Cool!
    Code:
    <html>
    <head>
    <SCRIPT LANGUAGE="JavaScript">
    
    
    
    <!-- Begin
    function addChar(input, character) {
    if(input.value == null || input.value == "0")
    input.value = character
    else
    input.value += character
    }
    function cos(form) {
    form.display.value = Math.cos(form.display.value);}
    function sin(form) {
    form.display.value = Math.sin(form.display.value);}
    function tan(form) {
    form.display.value = Math.tan(form.display.value);}
    function sqrt(form) {
    form.display.value = Math.sqrt(form.display.value);}
    function ln(form) {
    form.display.value = Math.log(form.display.value);}
    function exp(form) {
    form.display.value = Math.exp(form.display.value);}
    function sqrt(form) {
    form.display.value = Math.sqrt(form.display.value);}
    function deleteChar(input) {
    input.value = input.value.substring(0, input.value.length - 1)
    }
    function changeSign(input) {
    if(input.value.substring(0, 1) == "-")
    input.value = input.value.substring(1, input.value.length)
    else
    input.value = "-" + input.value
    }
    function compute(form)  {
    form.display.value = eval(form.display.value)}
    function square(form)  {
    form.display.value = eval(form.display.value) *
    eval(form.display.value)}
    function checkNum(str)  {
    for (var i = 0; i < str.length; i++) {
    var ch = str.substring(i, i+1)
    if (ch < "0" || ch > "9") {
    if (ch != "/" && ch != "*" && ch != "+" && ch !=
    "-" && ch != "."
    && ch != "(" && ch!= ")") {
    alert("invalid entry!")
    return false
             }
          }
       }
    return true
    }
    // End -->
    </SCRIPT>
    </heaD>
    <body>
    <!-- Demonstration -->
    <center><form>
    <input name="display" value="0" size=25>
        <br>
    <input type="button" value="   exp  " onClick="if (checkNum(this.form.display.value))
    { exp(this.form) }">
    <input type="button" value="    7    " onClick="addChar(this.form.display, '7')">
    <input type="button" value="    8    " onClick="addChar(this.form.display, '8')">
    <input type="button" value="    9    " onClick="addChar(this.form.display, '9')">
    <input type="button" value="    /    " onClick="addChar(this.form.display, '/')">
    <br>
    <input type="button" value="    ln    " onClick="if (checkNum(this.form.display.value))
    { ln(this.form) }">
    <input type="button" value="    4    " onClick="addChar(this.form.display, '4')">
    <input type="button" value="    5    " onClick="addChar(this.form.display, '5')">
    <input type="button" value="    6    " onClick="addChar(this.form.display, '6')">
    <input type="button" value="    *    " onClick="addChar(this.form.display, '*')">
    <br>
    <input type="button" value="   sqrt  " onClick="if (checkNum(this.form.display.value))
    { sqrt(this.form) }">
    <input type="button" value="    1    " onClick="addChar(this.form.display, '1')">
    <input type="button" value="    2    " onClick="addChar(this.form.display, '2')">
    <input type="button" value="    3    " onClick="addChar(this.form.display, '3')">
    <input type="button" value="    -    " onClick="addChar(this.form.display, '-')">
    <br>
    <input type="button" value="    sq   " onClick="if (checkNum(this.form.display.value))
    { square(this.form) }">
    <input type="button" value="   0     " onClick="addChar(this.form.display, '0')">
    <input type="button" value="    .    " onClick="addChar(this.form.display, '.')">
    <input type="button" value="   +/-   " onClick="changeSign(this.form.display)">
    <input type="button" value="    +    " onClick="addChar(this.form.display, '+')">
    <br>
    <input type="button" value="    (    " onClick="addChar(this.form.display, '(')">
    <input type="button" value="   cos   " onClick="if (checkNum(this.form.display.value))
    { cos(this.form) }">
    <input type="button" value="   sin   " onClick="if (checkNum(this.form.display.value))
    { sin(this.form) }">
    <input type="button" value="   tan   " onClick="if (checkNum(this.form.display.value))
    { tan(this.form) }">
    <input type="button" value="    )    " onClick="addChar(this.form.display, ')')">
    <br>
    <input type="button" value="  Clear  " onClick="this.form.display.value = 0 ">
    <input type="button" value=" Back Space  " onClick="deleteChar(this.form.display)">
    <input type="button" value="   Enter    " name="enter" onClick="if (checkNum(this.form.display.value))
    { compute(this.form) }">
    </FORM>
    </body>
    </html>

  2. #2

  3. #3
    Senior Member Array akash's Avatar
    Join Date
    Oct 2008
    Location
    Heaven (Earth)
    Posts
    500

    Default Re: Scientific Calculator

    Quote Originally Posted by manilaoffice View Post
    Wow, that nice I used learn java but only the basic one..Thank you for sharing that codes.
    It is not java. It is javascript.
    Java is different from the javascript

  4. #4

  5. #5
    Senior Member Array
    Join Date
    Jul 2009
    Posts
    103

    Default Re: Scientific Calculator

    Ya really very nice code. Thanks for sharing.

  6. #6
    Senior Member Array
    Join Date
    Jun 2009
    Posts
    192

    Default Re: Scientific Calculator

    That was great calculator using javascript, Is it also possible to make a calculator using php?

  7. #7
    Senior Member Array tanya1177's Avatar
    Join Date
    Aug 2008
    Location
    London
    Posts
    391

    Default Re: Scientific Calculator

    I also interesting in php calculator. Any ideas?

  8. #8
    Senior Member Array
    Join Date
    Mar 2011
    Posts
    110

    Default Re: Scientific Calculator

    Thanks for such a nice posting.It is a very useful tool,I definitely use it..............



Similar Threads

  1. Wind Chill Calculator
    By akash in forum Programming
    Replies: 0
    Last Post: 02-23-2009, 08:24 AM
  2. Adwords Keyword Calculator?
    By Jobs for 14 in forum Google
    Replies: 3
    Last Post: 12-09-2008, 05:27 AM
  3. Want scientific immortality? Name a sea worm (AP)
    By mike42 in forum Member Discussion
    Replies: 0
    Last Post: 06-30-2008, 04:54 PM
  4. Japan defends 'scientific' whale hunting at IWC (AFP)
    By mike42 in forum Member Discussion
    Replies: 0
    Last Post: 06-26-2008, 01:35 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO Forum | Web Hosting Forum | Websites For Sale |