[Webfunds-commits] java/webfunds/ricardian Contract.java

Ian Grigg iang@cypherpunks.ai
Sat, 17 Mar 2001 16:28:00 -0400 (AST)


iang        01/03/17 16:28:00

  Modified:    webfunds/ricardian Contract.java
  Log:
  added the getPrintableAmount method so that it is easy to print the total

Revision  Changes    Path
1.50      +25 -3     java/webfunds/ricardian/Contract.java

Index: Contract.java
===================================================================
RCS file: /home/webfunds/cvsroot/java/webfunds/ricardian/Contract.java,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- Contract.java	2001/02/27 01:28:26	1.49
+++ Contract.java	2001/03/17 20:27:59	1.50
@@ -1,4 +1,4 @@
-/* $Id: Contract.java,v 1.49 2001/02/27 01:28:26 iang Exp $
+/* $Id: Contract.java,v 1.50 2001/03/17 20:27:59 iang Exp $
  *
  * Copyright (c) Systemics Ltd 1995-1999 on behalf of
  * the WebFunds Development Team.  All Rights Reserved.
@@ -243,16 +243,37 @@
      *  Get a DecimalFormat object suitable for this Contract.
      *  If no call to setDecimalFormat() has been made,
      *  one is initialised from getDecimalFormatPattern().
+     *
+     *  Use like this:    
+     *      import java.text.DecimalFormat;
+     *      DecimalFormat df = con.getDecimalFormat();
+     *      double amount = con.getUnitsOfAccount((long)qty),
+     *      String val = df.format(amount);
      */
     public DecimalFormat getDecimalFormat()
     {
-        if (decimalFormat!= null)
+        if (decimalFormat != null)
            return decimalFormat;
 
-        decimalFormat= new DecimalFormat(getDecimalFormatPattern());
+        decimalFormat = new DecimalFormat(getDecimalFormatPattern());
         return decimalFormat ;
     }
 
+    /**
+     *  Get a printable string in unit of account.
+     *  If no call to setDecimalFormat() has been made,
+     *  one is initialised from getDecimalFormatPattern().
+     *
+     *  Use like this:    
+     */
+    public String getPrintableAmount(long qty)
+    {
+        DecimalFormat df = this.getDecimalFormat();
+        double amount = this.getUnitsOfAccount((long)qty);
+        String val = df.format(amount);
+        return val;
+    }
+
 
     /**
      *  unitsOfAccount = dollars, unitsOfContract = cents
@@ -796,6 +817,7 @@
 /////////// Names /////////////////////////////////////////
 
     public ItemId getId()         { return id ; }
+    public ItemId getItemId()     { return id ; }
     public String getUniqueName() { return name ; }
     public String getFileName()   { return fileName ; }