From 6154db914bbee088ac49cacf9722dee8909a36c4 Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 23 Oct 2003 16:09:34 +0000 Subject: [PATCH] Moved the currency{Pennies} from StringTool to StringUtil. Made wrappers in StringTool so we can keep using them. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1274 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../java/com/samskivert/util/StringUtil.java | 26 ++++++++++++++++--- .../com/samskivert/velocity/StringTool.java | 9 +++---- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/projects/samskivert/src/java/com/samskivert/util/StringUtil.java b/projects/samskivert/src/java/com/samskivert/util/StringUtil.java index 23ca74b3..922af657 100644 --- a/projects/samskivert/src/java/com/samskivert/util/StringUtil.java +++ b/projects/samskivert/src/java/com/samskivert/util/StringUtil.java @@ -1,9 +1,9 @@ // -// $Id: StringUtil.java,v 1.58 2003/10/08 23:52:50 ray Exp $ +// $Id: StringUtil.java,v 1.59 2003/10/23 16:09:34 eric Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne -// +// // This library is free software; you can redistribute it and/or modify it // under the terms of the GNU Lesser General Public License as published // by the Free Software Foundation; either version 2.1 of the License, or @@ -161,6 +161,22 @@ public class StringUtil return false; } + /** + * Converts a number representing dollars to a currency display string. + */ + public static String currency (double value) + { + return _curFormatter.format(value); + } + + /** + * Converts a number representing pennies to a currency display string. + */ + public static String currencyPennies (double value) + { + return currency(value / 100.0); + } + /** * Formats a floating point value with useful default rules; * ie. always display a digit to the left of the decimal and display @@ -509,7 +525,7 @@ public class StringUtil buf.append(closeBox); } else { - // fall back on the general purpose + // fall back on the general purpose toString(buf, val); } } @@ -1102,4 +1118,8 @@ public class StringUtil _ffmt.setMinimumFractionDigits(1); _ffmt.setMaximumFractionDigits(2); } + + /** Used to easily format numbers as currency. Bling Bling. */ + protected static NumberFormat _curFormatter = + NumberFormat.getCurrencyInstance(); } diff --git a/projects/samskivert/src/java/com/samskivert/velocity/StringTool.java b/projects/samskivert/src/java/com/samskivert/velocity/StringTool.java index 6d905229..178035c0 100644 --- a/projects/samskivert/src/java/com/samskivert/velocity/StringTool.java +++ b/projects/samskivert/src/java/com/samskivert/velocity/StringTool.java @@ -1,5 +1,5 @@ // -// $Id: StringTool.java,v 1.11 2003/10/08 23:52:50 ray Exp $ +// $Id: StringTool.java,v 1.12 2003/10/23 16:09:34 eric Exp $ // // samskivert library - useful routines for java programs // Copyright (C) 2001 Michael Bayne @@ -59,7 +59,7 @@ public class StringTool */ public static String currency (double value) { - return _curFormatter.format(value); + return StringUtil.currency(value); } /** @@ -67,7 +67,7 @@ public class StringTool */ public static String currencyPennies (double value) { - return currency(value / 100.0); + return StringUtil.currencyPennies(value); } /** @@ -77,7 +77,4 @@ public class StringTool { return HTMLUtil.makeParagraphs(text); } - - protected static NumberFormat _curFormatter = - NumberFormat.getCurrencyInstance(); }