Added a couple of useful functions for convertind double dollars or

pennies to strings.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@1234 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
eric
2003-10-01 22:58:31 +00:00
parent 20fd2a0bd7
commit b2b4e0ec7d
@@ -1,5 +1,5 @@
// //
// $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 // samskivert library - useful routines for java programs
// Copyright (C) 2001 Michael Bayne // Copyright (C) 2001 Michael Bayne
@@ -21,6 +21,7 @@
package com.samskivert.velocity; package com.samskivert.velocity;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.text.NumberFormat;
import com.samskivert.servlet.util.HTMLUtil; import com.samskivert.servlet.util.HTMLUtil;
import com.samskivert.util.StringUtil; import com.samskivert.util.StringUtil;
@@ -54,6 +55,22 @@ public class StringTool
return String.valueOf(value); 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. * Adds <p> tags between each pair of consecutive newlines.
*/ */
@@ -61,4 +78,7 @@ public class StringTool
{ {
return HTMLUtil.makeParagraphs(text); return HTMLUtil.makeParagraphs(text);
} }
protected static NumberFormat _curFormatter =
NumberFormat.getCurrencyInstance();
} }