数字の書式を変換するクラス
来源:互联网 发布:寻找客户的软件 编辑:程序博客网 时间:2024/05/01 10:53
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
/**
* 数字の書式を変換するクラス<BR>
*
* <PRE>
* 数字の書式を変換する
* </PRE>
*
* @author TCI xxx 2011/12/23
*
*/
public final class NumberUtil {
/** 定数DEFAULT_MONEY_FORMAT_STR1常用金額の書式 */
private static final String DEFAULT_MONEY_FORMAT_STR1 = "###,###,###.00";
/**
* 常用数字の書式を変換するメソッド<BR>
*
* <PRE>
* 常用数字の書式を変換するする
* </PRE>
*
* @param _number
* 処理の数字のパラメータ
* @return 数字の書式を変換する結果
*
*/
public static String numberFormat(int _number) {
NumberFormat numf = NumberFormat.getInstance();
return numf.format(_number);
}
/**
* 常用金額の書式を変換するメソッド<BR>
*
* <PRE>
* 常用金額の書式を変換するする
* </PRE>
*
* @param _money
* 処理の金額のパラメータ
* @return 金額の書式を変換する結果
*
*/
public static String moneyFormat(double _money) {
DecimalFormat decimalFormat = new DecimalFormat(
DEFAULT_MONEY_FORMAT_STR1);
return decimalFormat.format(_money);
}
/**
* 常用金額の書式を変換するメソッド<BR>
*
* <PRE>
* 常用金額の書式を変換するする
* </PRE>
*
* @param _money
* 処理の金額のパラメータ
* @return 金額の書式を変換する結果
*
*/
public static String moneyFormatZz(BigDecimal _money) {
String money = _money.toString();
int length = money.length();
int index = money.indexOf(".");
DecimalFormat decimalFormat = new DecimalFormat("###,###,###");
if (index == -1) {
String strMoney = decimalFormat.format(Double.parseDouble(money));
return strMoney;
} else {
String str0 = money.substring(index + 1, length);
if (str0.length() == 2) {
String str1 = str0.substring(0, 1);
String str2 = str0.substring(1, 2);
if ("0".equals(str2)) {
if ("0".equals(str1)) {
// 9999.00
String strZhengNum = money.substring(0, index);
String strZhengMoney = decimalFormat.format(Double
.parseDouble(strZhengNum));
return strZhengMoney;
} else {
// 9999.90
String strZhengNum = money.substring(0, index);
String strZhengMoney = decimalFormat.format(Double
.parseDouble(strZhengNum));
String strMoney = strZhengMoney + "." + str1;
return strMoney;
}
} else {
// 9999.99
String strXiaoNum = money.substring(index, length);
String strZhengNum = money.substring(0, index);
String strZhengMoney = decimalFormat.format(Double
.parseDouble(strZhengNum));
String strMoney = strZhengMoney + strXiaoNum;
return strMoney;
}
} else {
// 9999.Z
String str1 = str0.substring(0, 1);
if ("0".equals(str1)) {
// 9999.0
String strZhengNum = money.substring(0, index);
String strZhengMoney = decimalFormat.format(Double
.parseDouble(strZhengNum));
return strZhengMoney;
} else {
// 9999.9
String strXiaoNum = money.substring(index, length);
String strZhengNum = money.substring(0, index);
String strZhengMoney = decimalFormat.format(Double
.parseDouble(strZhengNum));
String strMoney = strZhengMoney + strXiaoNum;
return strMoney;
}
}
}
}
}
- 数字の書式を変換するクラス
- C#数字と文字列の変換
- 英数字の入力制御
- 数字
- 数字
- 数字:
- 数字
- 数字
- 数字
- 数字
- 数字
- 数字
- 数字
- 数字
- 数字
- 数字
- 二千零八年--晴れる--”数字の巡る”
- 数字関連の使用
- 文字列を判断するクラス
- Android: R cannot be resolved to a variable
- Intent中putExtra()方法用法
- 菜鸟从零开始的第一个应用上线记(一)
- dfsdf
- 数字の書式を変換するクラス
- 随机函数 rand()
- opencv2.4.0 + vc express 2008 配置
- C++学习方法
- mysql创建定时任务
- 修改时清除字段内容的SQL语句
- vb.net UltraChart画柱状图
- Java socket中isClose()和isConnected()
- 短网址功能实现