1 package org.paneris.jammyjoes.model; 2 3 import java.util.Locale; 4 5 import org.melati.util.StringUtils; 6 import org.paneris.jammyjoes.model.generated.ShopCurrencyBase; 7 import org.paneris.jammyjoes.util.JammyJoesUtil; 8 9 public class ShopCurrency extends ShopCurrencyBase { 10 public ShopCurrency() {} 11 12 public Locale toLocale() { 13 String[] parts = StringUtils.split(getLocale(), '_'); 14 if (parts.length > 2) return new Locale(parts[0], parts[1], parts[2]); 15 if (parts.length > 1) return new Locale(parts[0], parts[1]); 16 return null; 17 } 18 19 public double convertFromUK(double value) { 20 return JammyJoesUtil.roundTo2dp(value * getConversionrate().doubleValue()); 21 } 22 23 public double convertToUK(double value) { 24 return JammyJoesUtil.roundTo2dp(value / getConversionrate().doubleValue()); 25 } 26 27 public String convertFromUKandFormat(double value) { 28 return JammyJoesUtil.euroFormat(toLocale(),convertFromUK(value)); 29 } 30 }