📄 formatutils.java
字号:
/*
* @author : Pushkala
* @version : 1.0
*
* Development Environment : Oracle9i JDeveloper
*
* Name of the File : FormatUtils.java
*
* Creation / Modification History
* Pushkala 03-Jun-2002 Created
*
*/
package oracle.otnsamples.ibfbs.utils;
import java.util.StringTokenizer;
/**
* This class is called from the JSPs to format float value into String
*
* @version 1.0
* @since 1.0
*/
public class FormatUtils {
/**
* This method takes an input float value and returns a string
* with two decimal places.
*
* @param value float Value
* @return The String representation of the input float value
* @since 1.0
*/
public static String formatFloatToString(float value) {
String stringValue = "";
// Convert the input value
float interim = (float) ((int) (value * 100)) / 100;
stringValue = (new Float(interim)).toString();
StringTokenizer st = new StringTokenizer(stringValue, ".");
if (st.countTokens() == 2) { // If the string has a decimal
String str = st.nextToken(); // Ignore first portion of string
str = st.nextToken(); // Use the Decimal portion of the string
/* If the decimal portion has only one digit */
if (str.length() < 2) {
stringValue += "0"; // Append one zero in the decimal place
}
}
else { // Else, the string has no decimal places
stringValue += ".00"; // Append two zeroes in the decimal place
}
return stringValue;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -