diff --git a/src/java/com/samskivert/util/CurrencyUtil.java b/src/java/com/samskivert/util/CurrencyUtil.java index ad9f81b9..a5e8bcc2 100644 --- a/src/java/com/samskivert/util/CurrencyUtil.java +++ b/src/java/com/samskivert/util/CurrencyUtil.java @@ -29,8 +29,8 @@ import java.util.Locale; public class CurrencyUtil { /** - * Converts a number representing pennies to a currency display string - * using the supplied local. + * Converts a number representing pennies to a locale-appropriate currency + * display string using the supplied local. */ public static String currencyPennies (double value, Locale locale) { @@ -38,33 +38,30 @@ public class CurrencyUtil } /** - * Converts a number representing dollars to a currency display string - * using the supplied locale. + * Converts a number representing currency in the specified locale to a + * displayable string. */ public static String currency (double value, Locale locale) { - NumberFormat numberFormatter = - NumberFormat.getCurrencyInstance(locale); - - return currency(value, numberFormatter); + return currency(value, NumberFormat.getCurrencyInstance(locale)); } /** - * Converts a number representing pennies to a currency display string - * using the default local. + * Converts a number representing pennies to a dollars display string using + * the US local. */ - public static String currencyPennies (double value) + public static String dollarsPennies (double value) { - return currency(value / 100.0, _defaultFormatter); + return currency(value / 100.0, _dollarFormatter); } /** * Converts a number representing dollars to a currency display string - * using the default locale. + * using the US locale. */ - public static String currency (double value) + public static String dollars (double value) { - return currency(value, _defaultFormatter); + return currency(value, _dollarFormatter); } /** @@ -76,7 +73,7 @@ public class CurrencyUtil return nformat.format(value); } - /** A number format for the default local. */ - protected static NumberFormat _defaultFormatter = - NumberFormat.getCurrencyInstance(); + /** A number format for formatting dollars. */ + protected static NumberFormat _dollarFormatter = + NumberFormat.getCurrencyInstance(Locale.US); } diff --git a/src/java/com/samskivert/velocity/CurrencyTool.java b/src/java/com/samskivert/velocity/CurrencyTool.java index 885dc178..13b0f19d 100644 --- a/src/java/com/samskivert/velocity/CurrencyTool.java +++ b/src/java/com/samskivert/velocity/CurrencyTool.java @@ -41,6 +41,24 @@ public class CurrencyTool /** * Converts a number representing dollars to a currency display string. */ + public String dollars (double value) + { + return CurrencyUtil.dollars(value); + } + + /** + * Converts a number representing pennies to a displayable dollars value. + */ + public String dollarsPennies (double value) + { + return CurrencyUtil.dollars(value); + } + + /** + * Converts a number representing currency in the requester's locale to a + * display string. Note: you probably want to be using {@link + * #dollars}. + */ public String currency (double value) { return CurrencyUtil.currency(value, _req.getLocale()); @@ -48,6 +66,7 @@ public class CurrencyTool /** * Converts a number representing pennies to a currency display string. + * Note: you probably want to be using {@link #dollarsPennies}. */ public String currencyPennies (double value) { @@ -55,14 +74,14 @@ public class CurrencyTool } /** - * Velocity currently doesn't support floats, so we have to provide - * our own support to convert pennies to a dollar amount. + * Velocity currently doesn't support floats, so we have to provide our own + * support to convert pennies to a dollar amount. */ public String penniesToDollars (int pennies) { return "" + (pennies / 100.0); } - + /** The servlet request we are providing currency functionality for. */ protected HttpServletRequest _req; }