/* calc.js */ /* ---------------------- grobal変数 ----------------------------- */ g_total = 0; g_mark = '\0'; g_flg = false; /* --------------------------------------------------------------- */ function calc() /* 計算処理 */ { next = parseFloat(document.cal.out.value); if( (g_mark == '+') && (g_flg != true) ) { g_total += next; } else if( (g_mark == '-') && (g_flg != true) ) { g_total -= next; } else if( (g_mark == '*') && (g_flg != true) ) { g_total *= next; } else if( (g_mark == '/') && (g_flg != true) ) { g_total /= next; } else { g_total = next; } g_flg = true; document.cal.out.value = String(g_total); } function out_num(num) /* number表示処理 */ { data = document.cal.out.value; if( data == '0' || g_flg == true ) { if( num == '.' ) { document.cal.out.value = '0'.concat(num); /* 文字列の連結 */ } else { document.cal.out.value = num; } g_flg = false; } else { document.cal.out.value = data.concat(num); } } /* ------------------------ calc-key ------------------------------ */ function add() /* +押下時 */ { calc(); g_mark = '+'; } function down() /* -押下時 */ { calc(); g_mark = '-'; } function mlt() /* *押下時 */ { calc(); g_mark = '*'; } function div() /* /押下時 */ { calc(); g_mark = '/'; } function equ() /* =押下時 */ { g_flg = false; calc(); g_mark = '\0'; } /* ----------------------- number-key ----------------------------- */ function key0() /* 0押下時 */ { key = '0'; out_num(key); } function key1() /* 1押下時 */ { key = '1'; out_num(key); } function key2() /* 2押下時 */ { key = '2'; out_num(key); } function key3() /* 3押下時 */ { key = '3'; out_num(key); } function key4() /* 4押下時 */ { key = '4'; out_num(key); } function key5() /* 5押下時 */ { key = '5'; out_num(key); } function key6() /* 6押下時 */ { key = '6'; out_num(key); } function key7() /* 7押下時 */ { key = '7'; out_num(key); } function key8() /* 8押下時 */ { key = '8'; out_num(key); } function key9() /* 9押下時 */ { key = '9'; out_num(key); } function key_dot() /* "."押下時 */ { key = '.'; out_num(key); } /* ---------------------------------------------------------------- */ function rst() /* C押下時 */ { /* global変数初期化 */ g_total = 0; g_mark = '\0'; g_flg = false; document.cal.reset(); /* リセット */ }