<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">

<script Language='JavaScript'>

function HanToNum(HanStr, return_input){
var Jo = 0;
var Ek = 0;
var ChenMan = 0;
var BakMan = 0;
var SibMan = 0;
var Man = 0;
var El_;
var HanToNum = 0;

return_input.value = 0;

if(HanStr.length >= 2){
//if( HanStr.length % 2 == 0 ){
if(HanStr.indexOf("조") !=-1){
Jo = makeStr(Left(HanStr, HanStr.indexOf("조")));
Jo = Jo * 1000000000000;
HanStr = Right(HanStr, HanStr.length - HanStr.indexOf("조")-1);
}
if(HanStr.indexOf("억") !=-1){
Ek = makeStr(Left(HanStr, HanStr.indexOf("억")));
Ek = Ek * 100000000;
HanStr = Right(HanStr, HanStr.length - HanStr.indexOf("억")-1);
}
if(HanStr.indexOf("만") !=-1){
Man = makeStr(Left(HanStr, HanStr.indexOf("만")));
Man = Man * 10000;
//alert;("Man = "+Man);
HanStr = Right(HanStr, HanStr.length - HanStr.indexOf("만")-1);
//alert;("HanStr = "+HanStr);
//alert;("HanStr.length = "+HanStr.length);
}

if(HanStr.length != 0){
//alert;("HanStr2 = "+HanStr);
//alert;("before makeStr");
El_ = makeStr2(HanStr);
}else{
El_ = 0;
}
HanToNum = Jo + Ek + Man + El_;

//}
}

return_input.value = Format_comma(HanToNum);
}


function makeStr(patStr){

var Chen = 0;
var Bak = 0;
var Sib = 0;
var El2; //As Long

if(patStr.indexOf("천") !=-1){
Chen = make123(Left(patStr, patStr.indexOf("천")));
/*
alert;("Chen0 patStr = "+patStr);
alert;("Chen0 indexOf = "+patStr.indexOf("천"))
alert;("Chen1 = "+patStr.indexOf("천") - 1);
alert;("Chen2 Left = "+Left(patStr, patStr.indexOf("천")));
alert;("Chen2 = "+Chen);
*/
Chen = Chen * 1000;
patStr = Right(patStr, patStr.length - patStr.indexOf("천")-1);
}
//alert;("patStr = "+patStr);
if(patStr.indexOf("백") !=-1){
Bak = make123(Left(patStr, patStr.indexOf("백")));
Bak = Bak * 100;
patStr = Right(patStr, patStr.length - patStr.indexOf("백")-1);
}
if(patStr.indexOf("십") !=-1){

Sib = make123(Left(patStr, patStr.indexOf("십")));
Sib = Sib * 10;
//alert;("Sib = "+Sib);
patStr = Right(patStr, patStr.length - patStr.indexOf("십")-1);
}
if(patStr.length != 0){
El2 = make123(patStr);
}else{
El2 = 0;
}

makeStr = Chen + Bak + Sib + El2;
return makeStr;
}

function makeStr2(patStr){
var Chen = 0;
var Bak = 0;
var Sib = 0;
var El2; //As Long

if(patStr.indexOf("천") !=-1){
Chen = make123(Left(patStr, patStr.indexOf("천")));
/*
alert;("Chen0 patStr = "+patStr);
alert;("Chen0 indexOf = "+patStr.indexOf("천"))
alert;("Chen1 = "+patStr.indexOf("천") - 1);
alert;("Chen2 Left = "+Left(patStr, patStr.indexOf("천")));
alert;("Chen2 = "+Chen);
*/
Chen = Chen * 1000;
patStr = Right(patStr, patStr.length - patStr.indexOf("천")-1);
}
//alert;("patStr = "+patStr);
if(patStr.indexOf("백") !=-1){
Bak = make123(Left(patStr, patStr.indexOf("백")));
Bak = Bak * 100;
patStr = Right(patStr, patStr.length - patStr.indexOf("백")-1);
}
if(patStr.indexOf("십") !=-1){

Sib = make123(Left(patStr, patStr.indexOf("십")));
Sib = Sib * 10;
//alert;("Sib = "+Sib);
patStr = Right(patStr, patStr.length - patStr.indexOf("십")-1);
}
if(patStr.length != 0){
El2 = make123(patStr);
}else{
El2 = 0;
}

makeStr = Chen + Bak + Sib + El2;
return makeStr;
}

function Left(str, n){
if( n<=0 ){
return "";
}else if(n>String(str).length){
return str;
}else{
return String(str).substring(0,n);
}
}

function Right(str, n){
if( n<=0 ){
return "";
}else if(n>String(str).length){
return str;
}else{
var iLen = String(str).length;
return String(str).substring(iLen, iLen - n);
}
}

//금액 변환
function make123(patStr){
var make123 = 0;
if(patStr == "" || patStr == "일"){
make123 = 1;
}else if(patStr == "이"){
make123 = 2;
}else if(patStr == "삼"){
make123 = 3;
}else if(patStr == "사"){
make123 = 4;
}else if(patStr == "오"){
make123 = 5;
}else if(patStr == "육"){
make123 = 6;
}else if(patStr == "칠"){
make123 = 7;
}else if(patStr == "팔"){
make123 = 8;
}else if(patStr == "구"){
make123 = 9;
}
return make123;
}


// 숫자에 3자리마다 콤마찍기(현금표시)
function Format_comma(val1){
var newValue = val1+""; //숫자를 문자열로 변환
var len = newValue.length;
var ch="";
var j=1;
var formatValue="";

// 콤마제거
newValue = newValue.replace(/\,/gi, ' ');

// comma제거된 문자열 길이
len = newValue.length;

for(i=len ; i>0 ; i--){
ch = newValue.substring(i-1,i);
formatValue = ch + formatValue;
if ((j%3) == 0 && i>1 ){
formatValue=","+formatValue;
}
j++
}
return formatValue;
}

// 콤마제거
function Format_NoComma(val1){
return (val1+"").replace(/\,/gi, '');
}

</script>
</head>

<body>
한글금액을 숫자금액으로 자동변환
<form name="form" action="#" method="get">
<input type="text" name="A_EMONEY" size=18 maxLength=15 style="text-align:right" > 원&nbsp;
<input type="button" onclick = "HanToNum(   document.form.A_EMONEY.value,   document.form.EMONEY_HAN);" value="입력">
<input type="text" name="EMONEY_HAN" readonly style="border:1;" size="15"> 원
</form>
</body>
</html>

'Jop Tip' 카테고리의 다른 글

숫자금액을 한글금액으로 변환 자바스크립트  (0) 2012.04.26
ime-mode  (1) 2011.08.02
HTTP 1.1 status codes  (0) 2010.09.16
한글 영어 숫자 체크하기  (1) 2010.08.11
w i n d o w s 7  (2) 2010.07.16
Posted by omok
,