상호 환전 계산기 > AI 게시판

본문 바로가기
사이트 내 전체검색

AI 게시판

gemini 상호 환전 계산기

페이지 정보

profile_image
작성자 관리자
댓글 0건 조회 388회 작성일 25-05-23 10:30

본문

<script>

// 초기 환율 값 (사용자가 변경 가능)

// 1 미국 달러당 원화, 1 베트남 동당 원화

const defaultExchangeRates = {

"KRW": 1,

"USD": 1370.00,

"VND": 0.055

};


function convertCurrency() {

// 사용자 입력 환율 가져오기

const userRateUsd = parseFloat(document.getElementById("rateUsd").value);

const userRateVnd = parseFloat(document.getElementById("rateVnd").value);


// 유효성 검사 및 기본값 설정

const currentExchangeRates = {

"KRW": 1,

"USD": isNaN(userRateUsd) || userRateUsd <= 0 ? defaultExchangeRates.USD : userRateUsd,

"VND": isNaN(userRateVnd) || userRateVnd <= 0 ? defaultExchangeRates.VND : userRateVnd

};


const amount = parseFloat(document.getElementById("amount").value);

const fromCurrency = document.getElementById("fromCurrency").value;

const toCurrency = document.getElementById("toCurrency").value;

const resultDiv = document.getElementById("result");


if (isNaN(amount) || amount <= 0) {

resultDiv.textContent = "유효한 금액을 입력해주세요.";

resultDiv.style.color = "red";

return;

}


if (fromCurrency === toCurrency) {

resultDiv.textContent = "동일한 통화로는 환전할 수 없습니다.";

resultDiv.style.color = "orange";

return;

}


// 사용자 설정 환율을 사용하여 계산

const fromRate = currentExchangeRates[fromCurrency];

const toRate = currentExchangeRates[toCurrency];


if (!fromRate || !toRate) {

resultDiv.textContent = "환율 정보를 찾을 수 없습니다. 환율을 확인해주세요.";

resultDiv.style.color = "red";

return;

}


// 1. 입력된 금액을 먼저 원화(KRW)로 변환

const amountInKRW = amount * fromRate;


// 2. 원화(KRW)를 목표 통화로 변환

let convertedAmount = amountInKRW / toRate;


let displayFromCurrencyName;

let displayToCurrencyName;


// 통화 단위 이름 설정

switch (fromCurrency) {

case "KRW": displayFromCurrencyName = "원"; break;

case "USD": displayFromCurrencyName = "달러 (USD)"; break;

case "VND": displayFromCurrencyName = "동 (VND)"; break;

}

switch (toCurrency) {

case "KRW": displayToCurrencyName = "원"; break;

case "USD": displayToCurrencyName = "달러 (USD)"; break;

case "VND": displayToCurrencyName = "동 (VND)"; break;

}


// 베트남 동은 소수점 없이, 나머지는 소수점 둘째 자리까지

if (toCurrency === "VND") {

convertedAmount = Math.round(convertedAmount);

} else if (fromCurrency === "VND" && toCurrency === "KRW") {

convertedAmount = convertedAmount.toFixed(2);

} else {

convertedAmount = convertedAmount.toFixed(2);

}


resultDiv.textContent = `${Number(amount).toLocaleString()} ${displayFromCurrencyName}는 약 ${Number(convertedAmount).toLocaleString()} ${displayToCurrencyName} 입니다.`;

resultDiv.style.color = "#0056b3";

}

</script>

추천0 비추천0

첨부파일

댓글목록

등록된 댓글이 없습니다.

회원로그인

회원가입

접속자집계

오늘
1,409
어제
1,048
최대
2,110
전체
38,504
접속자 : 9 모바일버전

Copyright © NEION All rights reserved.