본문 바로가기
Nodejs

[Node.js]currency-converter-lt를 사용한 통화 변환

by teamnova 2023. 9. 2.

안녕하세요 이번시간에는 Nodejs 를 사용해 통화변환과 이를 표시할 때 해당 통화를 형식화하는 방법에 대해 알아보겠습니다.

먼저 필요한 npm 패키지를 설치합니다.

npm install currency-converter-lt currency-formatter

후에 코드작성은 아래와 같이 합니다.

const CC = require('currency-converter-lt');
const currencyFormatter = require('currency-formatter');

// USD에서 다른 통화로 변환하는 함수
async function convertFromUSD(toCurrency) {

    let currencyConverter = new CC({ from: "USD", to: toCurrency, amount: 1 });
    const response = await currencyConverter.convert();

    // 변환된 값을 형식화
    const formattedAmount = currencyFormatter.format(response, { code: toCurrency });

    console.log(`1 USD => ${formattedAmount} in ${toCurrency}`);
}

// KRW, EUR, JPY, GBP로 변환
convertFromUSD('KRW');
convertFromUSD('EUR');
convertFromUSD('JPY');
convertFromUSD('GBP');

 

 

통화 코드 목록

  • USD: 미국 달러
  • EUR: 유로
  • JPY: 일본 엔
  • GBP: 영국 파운드
  • AUD: 호주 달러 
  • ...

**통화 코드는 ISO 4217를 따릅니다. 참고링크는 아래 남겨놓겠습니다!

 

https://www.npmjs.com/package/currency-converter-lt

 

currency-converter-lt

A nodejs currency converter library that doesn't require subscribing to any API calls.. Latest version: 2.0.0, last published: 2 months ago. Start using currency-converter-lt in your project by running `npm i currency-converter-lt`. There are 5 other proje

www.npmjs.com

https://ko.wikipedia.org/wiki/ISO_4217

 

ISO 4217 - 위키백과, 우리 모두의 백과사전

위키백과, 우리 모두의 백과사전. 통화 코드는 여기로 연결됩니다. 비슷한 이름의 통화 기호에 관해서는 해당 문서를 참조하십시오. ISO 4217 코드(유로/EUR, 왼쪽 아래)로 표기된 비행기표. ISO 4217

ko.wikipedia.org