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:
@@ -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
|
// samskivert library - useful routines for java programs
|
||||||
// Copyright (C) 2001 Michael Bayne
|
// Copyright (C) 2001 Michael Bayne
|
||||||
//
|
//
|
||||||
// This library is free software; you can redistribute it and/or modify it
|
// 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
|
// 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
|
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||||
@@ -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();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user