KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > utils > MathUtils


1 /* *****************************************************************************
2  * MathUtils.java
3  * ****************************************************************************/

4
5 /* J_LZ_COPYRIGHT_BEGIN *******************************************************
6 * Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
7 * Use is subject to license terms. *
8 * J_LZ_COPYRIGHT_END *********************************************************/

9
10 package org.openlaszlo.utils;
11
12 import java.lang.Math JavaDoc;
13 /**
14  * A utility class containing math utility functions.
15  */

16
17 public class MathUtils {
18     /**
19      * @param d the double to format
20      * @param n the number of places past the decimal place
21      */

22     public static String JavaDoc formatDouble(double d, int n) {
23         int x = (int)Math.pow(10, n);
24         return Double.toString((double)(( (int)(x*d) ) / (double)x));
25
26     }
27
28     /**
29      * @return hex representation of byte.
30      */

31     public static String JavaDoc byteToHexString(byte b) {
32         int left = (int)( (b & 0xf0) >> 4 );
33         int right = (int)( b & 0x0f );
34         return Integer.toHexString(left) + Integer.toHexString(right);
35     }
36 }
37
38
Popular Tags