diff --git a/projects/samskivert/src/java/com/samskivert/velocity/StringTool.java b/projects/samskivert/src/java/com/samskivert/velocity/StringTool.java index ad672507..df7f7ff4 100644 --- a/projects/samskivert/src/java/com/samskivert/velocity/StringTool.java +++ b/projects/samskivert/src/java/com/samskivert/velocity/StringTool.java @@ -1,9 +1,9 @@ // -// $Id: StringTool.java,v 1.6 2002/12/30 04:55:01 mdb Exp $ +// $Id: StringTool.java,v 1.7 2003/10/01 22:58:31 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 @@ -21,6 +21,7 @@ package com.samskivert.velocity; import java.net.URLEncoder; +import java.text.NumberFormat; import com.samskivert.servlet.util.HTMLUtil; import com.samskivert.util.StringUtil; @@ -54,6 +55,22 @@ public class StringTool return String.valueOf(value); } + /** + * Converts a number representing dollars to a currency display string. + */ + public String currency (double value) + { + return _curFormatter.format(value); + } + + /** + * Converts a number representing pennies to a currency display string. + */ + public String currencyPennies (double value) + { + return _curFormatter.format(value/100.0); + } + /** * Adds <p> tags between each pair of consecutive newlines. */ @@ -61,4 +78,7 @@ public class StringTool { return HTMLUtil.makeParagraphs(text); } + + protected static NumberFormat _curFormatter = + NumberFormat.getCurrencyInstance(); }