001/* 002 * jPOS Project [http://jpos.org] 003 * Copyright (C) 2000-2026 jPOS Software SRL 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Affero General Public License as 007 * published by the Free Software Foundation, either version 3 of the 008 * License, or (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Affero General Public License for more details. 014 * 015 * You should have received a copy of the GNU Affero General Public License 016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 017 */ 018 019package org.jpos.iso; 020 021import java.io.Serializable; 022 023 024/** 025 * ISO Currency Conversion package 026 * 027 * @author salaman@teknos.com 028 * @version $Id$ 029 */ 030public class Currency implements Serializable 031{ 032 String alphacode; 033 int isocode; 034 int numdecimals; 035 036 public Currency(String alphacode, int isocode, int numdecimals) 037 { 038 this.alphacode = alphacode; 039 this.isocode = isocode; 040 this.numdecimals = numdecimals; 041 } 042 043 public int getDecimals() 044 { 045 return numdecimals; 046 } 047 048 public int getIsoCode() 049 { 050 return isocode; 051 } 052 053 public String getAlphaCode() 054 { 055 return alphacode; 056 } 057 058 public String formatAmountForISOMsg(double amount) 059 { 060 try 061 { 062 double m = Math.pow(10, getDecimals()) * amount; 063 return ISOUtil.zeropad(String.valueOf(Math.round(m)), 12); 064 } 065 catch (ISOException e) 066 { 067 throw new IllegalArgumentException("Failed to convert amount",e); 068 } 069 } 070 071 public double parseAmountFromISOMsg(String isoamount) 072 { 073 return Double.parseDouble(isoamount)/Math.pow(10, getDecimals()); 074 } 075 076 @Override 077 public String toString() 078 { 079 return "Currency{" + 080 "alphacode='" + alphacode + '\'' + 081 ", isocode=" + isocode + 082 ", numdecimals=" + numdecimals + 083 '}'; 084 } 085}