KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > raptus > owxv3 > api > FormatterObject


1 /*
2  * eAdmin/OWX
3  * Copyright (C) 1996-2003 OWX-Project Team <owx-team@gmx.net>
4  */

5
6 package com.raptus.owxv3.api;
7
8 import java.text.NumberFormat JavaDoc;
9 import java.util.*;
10
11 public class FormatterObject extends Object JavaDoc
12 {
13     protected Locale locale = null;
14     
15     public FormatterObject(Locale locale)
16     {
17         this.locale = locale;
18     }
19     
20     /**
21      * formatting like this: 99'999.99 SFr
22      */

23     public String JavaDoc formatPriceForList(String JavaDoc unformatted)
24     {
25         String JavaDoc retval = unformatted;
26         StringTokenizer st = new StringTokenizer((String JavaDoc) unformatted);
27         if(st.countTokens() == 2)
28         {
29             String JavaDoc currency = st.nextToken();
30             double price = new Double JavaDoc(st.nextToken()).doubleValue();
31             NumberFormat JavaDoc nf = NumberFormat.getInstance(locale);
32             nf.setMaximumFractionDigits(2);
33             nf.setMinimumFractionDigits(2);
34             retval = nf.format(price) + " " + currency;
35         }
36     
37         return retval;
38     }
39
40     /**
41      * formatting like this: 99'999.99 SFr or "inkl." if zero
42      */

43     public String JavaDoc formatNKostenForList(String JavaDoc unformatted)
44     {
45       return formatNKostenForList(unformatted, "inkl.");
46     }
47
48     /**
49      * formatting like this: 99'999.99 SFr or <zeroval> if zero
50      */

51     public String JavaDoc formatNKostenForList(String JavaDoc unformatted, String JavaDoc zeroval)
52     {
53         String JavaDoc retval = unformatted;
54         StringTokenizer st = new StringTokenizer((String JavaDoc) unformatted);
55         if(st.countTokens() == 2)
56         {
57             String JavaDoc currency = st.nextToken();
58             double price = new Double JavaDoc(st.nextToken()).doubleValue();
59             if(price == 0.0)
60             {
61                 retval = zeroval;
62             }
63             else
64             {
65                 NumberFormat JavaDoc nf = NumberFormat.getInstance(locale);
66                 nf.setMaximumFractionDigits(2);
67                 nf.setMinimumFractionDigits(2);
68                 retval = nf.format(price) + " " + currency;
69             }
70         }
71     
72         return retval;
73     }
74 }
75
76 // eof
77

78
79
Popular Tags