當前位置:首頁 » 編程語言 » java金額轉換

java金額轉換

發布時間: 2023-02-15 11:51:05

A. java如何將數字轉為中文大寫

import org.apache.commons.lang3.StringUtils;

/**
* @Title: ConvertUpMoney
* @Description: 將數字金額轉換為大寫中文金額
* @date: 2019年6月18日 下午10:52:27
*/
public class ConvertUpMoney {

// 大寫數字
private static final String[] NUMBERS = {"零","壹","貳","叄","肆","伍","陸","柒","捌","玖"};
// 整數部分的單位
private static final String[] IUNIT = {"元","拾","佰","仟","萬","拾","佰","仟","億","拾","佰","仟","萬","拾","佰","仟"};
// 小數部分的單位
private static final String[] DUNIT = {"角","分","厘"};

/**
* 轉換為大寫的中文金額
* @param str 字元串類型的 金額數字
* @return
*/
public static String toChinese(String str) {
// 判斷輸入的金額字元串是否符合要求
if (StringUtils.isBlank(str) || !str.matches("(-)?[\\d]*(.)?[\\d]*")) {
return "抱歉,請輸入數字!";
}

if("0".equals(str) || "0.00".equals(str) || "0.0".equals(str)) {
return "零元";
}

// 判斷金額數字中是否存在負號"-"
boolean flag = false;
if(str.startsWith("-")){
// 標志位,標志此金額數字為負數
flag = true;
str = str.replaceAll("-", "");
}

// 去掉金額數字中的逗號","
str = str.replaceAll(",", "");
String integerStr;//整數部分數字
String decimalStr;//小數部分數字

// 初始化:分離整數部分和小數部分
if(str.indexOf(".")>0) {
integerStr = str.substring(0,str.indexOf("."));
decimalStr = str.substring(str.indexOf(".") + 1);
}else if(str.indexOf(".")==0) {
integerStr = "";
decimalStr = str.substring(1);
}else {
integerStr = str;
decimalStr = "";
}

// beyond超出計算能力,直接返回
if(integerStr.length()>IUNIT.length) {
return "超出計算能力!";
}

// 整數部分數字
int[] integers = toIntArray(integerStr);
// 判斷整數部分是否存在輸入012的情況
if (integers.length>1 && integers[0] == 0) {
return "抱歉,輸入數字不符合要求!";
}
// 設置萬單位
boolean isWan = isWan5(integerStr);
// 小數部分數字
int[] decimals = toIntArray(decimalStr);
// 返回最終的大寫金額
String result = getChineseInteger(integers, isWan) + getChineseDecimal(decimals);
if(flag){
// 如果是負數,加上"負"
return "負" + result;
}else{
return result;
}
}

/**
* 將字元串轉為int數組
* @param number 數字
* @return
*/
private static int[] toIntArray(String number) {
int[] array = new int[number.length()];
for(int i = 0;i<number.length();i++) {
array[i] = Integer.parseInt(number.substring(i,i+1));
}
return array;
}

/**
* 將整數部分轉為大寫的金額
* @param integers 整數部分數字
* @param isWan 整數部分是否已經是達到【萬】
* @return
*/
public static String getChineseInteger(int[] integers,boolean isWan) {
StringBuffer chineseInteger = new StringBuffer("");
int length = integers.length;
if (length == 1 && integers[0] == 0) {
return "";
}
for(int i=0; i<length; i++) {
String key = "";
if(integers[i] == 0) {
if((length - i) == 13)//萬(億)
key = IUNIT[4];
else if((length - i) == 9) {//億
key = IUNIT[8];
}else if((length - i) == 5 && isWan) {//萬
key = IUNIT[4];
}else if((length - i) == 1) {//元
key = IUNIT[0];
}
if((length - i)>1 && integers[i+1]!=0) {
key += NUMBERS[0];
}
}
chineseInteger.append(integers[i]==0?key:(NUMBERS[integers[i]]+IUNIT[length - i -1]));
}
return chineseInteger.toString();
}

/**
* 將小數部分轉為大寫的金額
* @param decimals 小數部分的數字
* @return
*/
private static String getChineseDecimal(int[] decimals) {
StringBuffer chineseDecimal = new StringBuffer("");
for(int i = 0;i<decimals.length;i++) {
if(i == 3) {
break;
}
chineseDecimal.append(decimals[i]==0?"":(NUMBERS[decimals[i]]+DUNIT[i]));
}
return chineseDecimal.toString();
}

/**
* 判斷當前整數部分是否已經是達到【萬】
* @param integerStr 整數部分數字
* @return
*/
private static boolean isWan5(String integerStr) {
int length = integerStr.length();
if(length > 4) {
String subInteger = "";
if(length > 8) {
subInteger = integerStr.substring(length- 8,length -4);
}else {
subInteger = integerStr.substring(0,length - 4);
}
return Integer.parseInt(subInteger) > 0;
}else {
return false;
}
}

// Test
public static void main(String[] args) {
String number = "12.56";
System.out.println(number+": "+ConvertUpMoney.toChinese(number));

number = "1234567890563886.123";
System.out.println(number+": "+ConvertUpMoney.toChinese(number));

number = "1600";
System.out.println(number+": "+ConvertUpMoney.toChinese(number));

number = "156,0";
System.out.println(number+": "+ConvertUpMoney.toChinese(number));

number = "-156,0";
System.out.println(number+": "+ConvertUpMoney.toChinese(number));

number = "0.12";
System.out.println(number+": "+ConvertUpMoney.toChinese(number));

number = "0.0";
System.out.println(number+": "+ConvertUpMoney.toChinese(number));

number = "01.12";
System.out.println(number+": "+ConvertUpMoney.toChinese(number));

number = "0125";
System.out.println(number+": "+ConvertUpMoney.toChinese(number));

number = "-0125";
System.out.println(number+": "+ConvertUpMoney.toChinese(number));

number = "sdw5655";
System.out.println(number+": "+ConvertUpMoney.toChinese(number));

System.out.println(null+": "+ConvertUpMoney.toChinese(null));
}
}

B. java金額轉換的問題,想要保留小數點後兩位,這樣會下標越界該怎麼改

哈?你的程序好復雜,我都沒看明白

BigDecimal直接設置小數並設置四捨五入的方式不就好了嗎?

C. Java中,怎麼將一段浮點數值轉換成人民幣格式例如將12004567.866轉換成 :壹千貳百萬

直接通過以下介面類方法實現即可:importjava.math.BigDecimal;/***金額工具類**@authorzn**@Date2013-2-1*@[email protected]*/publicclassMoneyUtil{privatestaticfinalintDFT_SCALE=2;/**大寫數字*/privatestaticfinalString[]NUMBERS={"零","壹","貳","叄","肆","伍","陸","柒","捌","玖"};/**整數部分的單位*/privatestaticfinalString[]IUNIT={"元","拾","佰","仟","萬","拾","佰","仟","億","拾","佰","仟","萬","拾","佰","仟"};/**小數部分的單位*/privatestaticfinalString[]DUNIT={"角","分","厘"};/***得到大寫金額。*/publicstaticStringtoChinese(Stringstr){str=str.replaceAll(",","");//去掉","StringintegerStr;//整數部分數字StringdecimalStr;//小數部分數字//初始化:分離整數部分和小數部分if(str.indexOf(".")>0){integerStr=str.substring(0,str.indexOf("."));decimalStr=str.substring(str.indexOf(".")+1);}elseif(str.indexOf(".")==0){integerStr="";decimalStr=str.substring(1);}else{integerStr=str;decimalStr="";}//integerStr去掉首0,不必去掉decimalStr的尾0(超出部分捨去)if(!integerStr.equals("")){integerStr=Long.toString(Long.parseLong(integerStr));if(integerStr.equals("0")){integerStr="";}}//overflow超出處理能力,直接返回if(integerStr.length()>IUNIT.length){System.out.println(str+":超出處理能力");returnstr;}int[]integers=toArray(integerStr);//整數部分數字booleanisMust5=isMust5(integerStr);//設置萬單位int[]decimals=toArray(decimalStr);//小數部分數字returngetChineseInteger(integers,isMust5)+getChineseDecimal(decimals);}/***整數部分和小數部分轉換為數組,從高位至低位*/privatestaticint[]toArray(Stringnumber){int[]array=newint[number.length()];for(inti=0;i1&&integers[i+1]!=0)key+=NUMBERS[0];}chineseInteger.append(integers[i]==0?key:(NUMBERS[integers[i]]+IUNIT[length-i-1]));}returnchineseInteger.toString();}/***得到中文金額的小數部分。*/(int[]decimals){StringBufferchineseDecimal=newStringBuffer("");for(inti=0;i4){StringsubInteger="";if(length>8){//TODO12-9-17//取得從低位數,第5到第8位的字串subInteger=integerStr.substring(length-8,length-4);}else{subInteger=integerStr.substring(0,length-4);}returnInteger.parseInt(subInteger)>0;}else{returnfalse;}}/***BigDecimal相乘,四捨五入保留0位**@parama*@paramb*@returna*b*/publicstaticBigDecimalmutiply(Stringa,Stringb,introundingMode){BigDecimalbd=newBigDecimal(a);returnbd.multiply(newBigDecimal(b)).setScale(DFT_SCALE,roundingMode);}/***BigDecimal相除,四捨五入保留兩位**@parama*@paramb*@returna/b*/publicstaticBigDecimaldiv(Stringa,Stringb,introundingMode){BigDecimaldecimal1=newBigDecimal(a);BigDecimaldecimal2=newBigDecimal(b);returndecimal1.divide(decimal2,DFT_SCALE,roundingMode);}/***BigDecimal相加,四捨五入保留兩位**@parama*@paramb*@returna+b*/publicstaticBigDecimalsum(Stringa,Stringb,introundingMode){BigDecimaldecimal1=newBigDecimal(a);BigDecimaldecimal2=newBigDecimal(b);//DecimalFormatformat=newDecimalFormat("#0.00");returndecimal1.add(decimal2).setScale(DFT_SCALE,roundingMode);}/***BigDecimal相減,四捨五入保留兩位**@parama*@paramb*@returna+b*/publicstaticBigDecimalsub(Stringa,Stringb,introundingMode){BigDecimaldecimal1=newBigDecimal(a);BigDecimaldecimal2=newBigDecimal(b);//DecimalFormatformat=newDecimalFormat("#0.00");returndecimal1.subtract(decimal2).setScale(DFT_SCALE,roundingMode);}/***100.00為10000**@parama*@return*/publicstaticBigDecimalformat(Stringa,introundingMode){returnnewBigDecimal(a).multiply(newBigDecimal(100)).setScale(0,roundingMode);}publicstaticvoidmain(String[]args){Stringnumber="54452";System.out.println(number+""+MoneyUtil.toChinese(number));number="30200";System.out.println(number+""+MoneyUtil.toChinese(number));number="30000.05";System.out.println(number+""+MoneyUtil.toChinese(number));number="30000.00";System.out.println(number+""+MoneyUtil.toChinese(number));}}備註:最後面的main方法是具體的調用。

D. Java 關於中文大寫金額與阿拉伯數字 互相轉換的問題(eclipse版)

package test.format;import java.text.NumberFormat;import java.util.HashMap;public class SimpleMoneyFormat {
public static final String EMPTY = "";public static final String ZERO = "零";public static final String ONE = "壹";public static final String TWO = "貳";public static final String THREE = "叄";public static final String FOUR = "肆"; public static final String FIVE = "伍";public static final String SIX = "陸";public static final String SEVEN = "柒"; public static final String EIGHT = "捌"; public static final String NINE = "玖"; public static final String TEN = "拾"; public static final String HUNDRED = "佰"; public static final String THOUSAND = "仟"; public static final String TEN_THOUSAND = "萬"; public static final String HUNDRED_MILLION = "億"; public static final String YUAN = "元"; public static final String JIAO = "角"; public static final String FEN = "分"; public static final String DOT = "."; private static SimpleMoneyFormat formatter = null;private HashMap chineseNumberMap = new HashMap(); private HashMap chineseMoneyPattern = new HashMap(); private NumberFormat numberFormat = NumberFormat.getInstance(); private SimpleMoneyFormat() { numberFormat.setMaximumFractionDigits(4); numberFormat.setMinimumFractionDigits(2); numberFormat.setGroupingUsed(false); chineseNumberMap.put("0", ZERO); chineseNumberMap.put("1", ONE); chineseNumberMap.put("2", TWO); chineseNumberMap.put("3", THREE); chineseNumberMap.put("4", FOUR); chineseNumberMap.put("5", FIVE); chineseNumberMap.put("6", SIX); chineseNumberMap.put("7", SEVEN); chineseNumberMap.put("8", EIGHT); chineseNumberMap.put("9", NINE); chineseNumberMap.put(DOT, DOT); chineseMoneyPattern.put("1", TEN); chineseMoneyPattern.put("2", HUNDRED); chineseMoneyPattern.put("3", THOUSAND); chineseMoneyPattern.put("4", TEN_THOUSAND); chineseMoneyPattern.put("5", TEN); chineseMoneyPattern.put("6", HUNDRED); chineseMoneyPattern.put("7", THOUSAND); chineseMoneyPattern.put("8", HUNDRED_MILLION); }
public static SimpleMoneyFormat getInstance() { if (formatter == null) formatter = new SimpleMoneyFormat(); return formatter; }
public String format(String moneyStr) { checkPrecision(moneyStr); String result; result = convertToChineseNumber(moneyStr); result = addUnitsToChineseMoneyString(result); return result; } public String format(double moneyDouble) { return format(numberFormat.format(moneyDouble)); } public String format(int moneyInt) { return format(numberFormat.format(moneyInt));
} public String format(long moneyLong) { return format(numberFormat.format(moneyLong)); }
public String format(Number moneyNum) { return format(numberFormat.format(moneyNum)); }
private String convertToChineseNumber(String moneyStr) { String result; StringBuffer cMoneyStringBuffer = new StringBuffer(); for (int i = 0; i < moneyStr.length(); i++) { cMoneyStringBuffer.append(chineseNumberMap.get(moneyStr.substring(i, i + 1))); }
//拾佰仟萬億等都是漢字裡面才有的單位,加上它們 int indexOfDot = cMoneyStringBuffer.indexOf(DOT); int moneyPatternCursor = 1; for (int i = indexOfDot - 1; i > 0; i--) { cMoneyStringBuffer.insert(i, chineseMoneyPattern.get(EMPTY + moneyPatternCursor)); moneyPatternCursor = moneyPatternCursor == 8 ? 1 : moneyPatternCursor + 1; } String fractionPart = cMoneyStringBuffer.substring(cMoneyStringBuffer.indexOf(".")); cMoneyStringBuffer.delete(cMoneyStringBuffer.indexOf("."), cMoneyStringBuffer.length()); while (cMoneyStringBuffer.indexOf("零拾") != -1) {
cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零拾"), cMoneyStringBuffer.indexOf("零拾") + 2, ZERO);
} while (cMoneyStringBuffer.indexOf("零佰") != -1) {
cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零佰"), cMoneyStringBuffer.indexOf("零佰") + 2, ZERO);
}while (cMoneyStringBuffer.indexOf("零仟") != -1) {
cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零仟"), cMoneyStringBuffer.indexOf("零仟") + 2, ZERO);
}while (cMoneyStringBuffer.indexOf("零萬") != -1) {
cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零萬"), cMoneyStringBuffer.indexOf("零萬") + 2, TEN_THOUSAND);
} while (cMoneyStringBuffer.indexOf("零億") != -1) {
cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零億"), cMoneyStringBuffer.indexOf("零億") + 2, HUNDRED_MILLION); } while (cMoneyStringBuffer.indexOf("零零") != -1) {
cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零零"), cMoneyStringBuffer.indexOf("零零") + 2, ZERO);
} if (cMoneyStringBuffer.lastIndexOf(ZERO) == cMoneyStringBuffer.length() - 1) cMoneyStringBuffer.delete(cMoneyStringBuffer.length() - 1, cMoneyStringBuffer.length()); cMoneyStringBuffer.append(fractionPart);
result = cMoneyStringBuffer.toString(); return result; }private String addUnitsToChineseMoneyString(String moneyStr) { String result; StringBuffer cMoneyStringBuffer = new StringBuffer(moneyStr); int indexOfDot = cMoneyStringBuffer.indexOf(DOT); cMoneyStringBuffer.replace(indexOfDot, indexOfDot + 1, YUAN); cMoneyStringBuffer.insert(cMoneyStringBuffer.length() - 1, JIAO); cMoneyStringBuffer.insert(cMoneyStringBuffer.length(), FEN); if (cMoneyStringBuffer.indexOf("零角零分") != -1)//沒有零頭,加整
cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零角零分"), cMoneyStringBuffer.length(), "整"); else if (cMoneyStringBuffer.indexOf("零分") != -1)//沒有零分,加整 cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零分"), cMoneyStringBuffer.length(), "整");
else { if(cMoneyStringBuffer.indexOf("零角")!=-1)
cMoneyStringBuffer.delete(cMoneyStringBuffer.indexOf("零角"),cMoneyStringBuffer.indexOf("零角")+2);
tmpBuffer.append("整"); } result = cMoneyStringBuffer.toString(); return result; } private void checkPrecision(String moneyStr) {
int fractionDigits = moneyStr.length() - moneyStr.indexOf(DOT) - 1; if (fractionDigits > 2) throw new RuntimeException("金額" + moneyStr + "的小數位多於兩位。"); //精度不能比分低 }public static void main(String args[]) { System.out.println(getInstance().format(new Double(10010001.01))); }}

E. java如何把大寫的金額改成小寫

/**
* @(#)SimpleMoneyFormat.java
*
*金額轉換,阿拉伯數字的金額轉換為中國傳統的形式輸出
* @lpxuan
* @version 1.00 2010/7/31
*/

import java.text.NumberFormat;
import java.util.HashMap;
import java.lang.StringBuffer;

public class SimpleMoneyFormat {

public static final String EMPTY="";
public static final String ZERO="零";
public static final String ONE="壹";
public static final String TWO="貳";
public static final String THREE="叄";
public static final String FOUR="肆";
public static final String FIVE="伍";
public static final String SIX="陸";
public static final String SEVEN="柒";
public static final String EIGHT="捌";
public static final String NINE="玖";
public static final String TEN="拾";
public static final String HUNDRED="佰";
public static final String THOUSAND="仟";
public static final String TEN_THOUSAND="萬";
public static final String HUNDRED_MILLION="億";
public static final String YUAN="元";
public static final String JIAO="角";
public static final String FEN="分";
public static final String DOT=".";

private static SimpleMoneyFormat formatter=null;
private HashMap chineseNumberMap=new HashMap();
private HashMap chineseMoenyPattern=new HashMap();
private NumberFormat numberFormat=NumberFormat.getInstance();

//私有構造函數
private SimpleMoneyFormat() {
numberFormat.setMaximumFractionDigits(4);
numberFormat.setMinimumFractionDigits(2);
numberFormat.setGroupingUsed(false);

chineseNumberMap.put("0",ZERO);
chineseNumberMap.put("1",ONE);
chineseNumberMap.put("2",TWO);
chineseNumberMap.put("3",THREE);
chineseNumberMap.put("4",FOUR);
chineseNumberMap.put("5",FIVE);
chineseNumberMap.put("6",SIX);
chineseNumberMap.put("7",SEVEN);
chineseNumberMap.put("8",EIGHT);
chineseNumberMap.put("9",NINE);
chineseNumberMap.put(DOT,DOT);

chineseMoenyPattern.put("1",TEN);
chineseMoenyPattern.put("2",HUNDRED);
chineseMoenyPattern.put("3",THOUSAND);
chineseMoenyPattern.put("4",TEN_THOUSAND);
chineseMoenyPattern.put("5",TEN);
chineseMoenyPattern.put("6",HUNDRED);
chineseMoenyPattern.put("7",THOUSAND);
chineseMoenyPattern.put("8",HUNDRED_MILLION);
}

//單例模式
public static SimpleMoneyFormat getInstance(){
if(formatter==null)
formatter=new SimpleMoneyFormat();
return formatter;
}

public String format(String moneyStr){
checkPrecision(moneyStr);
String result;
result=convertToChineseNumber(moneyStr);
result=addUnitsToChineseMoenyString(result);
return result;
}

public String format(double moneyDouble){
return format(numberFormat.format(moneyDouble));
}

public String format(int moneyInt){
return format(numberFormat.format(moneyInt));
}

public String format(long moneyLong){
return format(numberFormat.format(moneyLong));
}

public String format(Number moneyNum){
return format(numberFormat.format(moneyNum));
}

private String convertToChineseNumber(String moneyStr){
String result;
StringBuffer cMoneyStringBuffer =new StringBuffer();
for(int i=0;i<moneyStr.length();i++){
cMoneyStringBuffer.append(chineseNumberMap.
get(moneyStr.substring(i,i+1)));
}

int indexOfDot=cMoneyStringBuffer.indexOf(DOT);
int moneyPatternCursor=1;
for(int i=indexOfDot-1;i>0;i--){
cMoneyStringBuffer.insert(i,
chineseMoenyPattern.get(EMPTY+moneyPatternCursor));
moneyPatternCursor=moneyPatternCursor==
8?1:moneyPatternCursor+1;
}

String fractionPart=cMoneyStringBuffer.substring(
cMoneyStringBuffer.indexOf("."));
cMoneyStringBuffer.delete(
cMoneyStringBuffer.indexOf("."),
cMoneyStringBuffer.length());
while(cMoneyStringBuffer.indexOf("零拾")!=-1){
cMoneyStringBuffer.replace(
cMoneyStringBuffer.indexOf("零拾"),
cMoneyStringBuffer.indexOf("零拾")+2,ZERO);
}
while(cMoneyStringBuffer.indexOf("零佰")!=-1){
cMoneyStringBuffer.replace(
cMoneyStringBuffer.indexOf("零佰"),
cMoneyStringBuffer.indexOf("零佰")+2,ZERO);
}
while(cMoneyStringBuffer.indexOf("零仟")!=-1){
cMoneyStringBuffer.replace(
cMoneyStringBuffer.indexOf("零仟"),
cMoneyStringBuffer.indexOf("零仟")+2,ZERO);
}
while(cMoneyStringBuffer.indexOf("零萬")!=-1){
cMoneyStringBuffer.replace(
cMoneyStringBuffer.indexOf("零萬"),
cMoneyStringBuffer.indexOf("零萬")+2,TEN_THOUSAND);
}
while(cMoneyStringBuffer.indexOf("零億")!=-1){
cMoneyStringBuffer.replace(
cMoneyStringBuffer.indexOf("零億"),
cMoneyStringBuffer.indexOf("零億")+2,HUNDRED_MILLION);
}
while(cMoneyStringBuffer.indexOf("零零")!=-1){
cMoneyStringBuffer.replace(
cMoneyStringBuffer.indexOf("零零"),
cMoneyStringBuffer.indexOf("零零")+2,ZERO);
}
if(cMoneyStringBuffer.lastIndexOf(ZERO)
==cMoneyStringBuffer.length()-1){
cMoneyStringBuffer.delete(
cMoneyStringBuffer.length()-1,
cMoneyStringBuffer.length());
}
cMoneyStringBuffer.append(fractionPart);
result=cMoneyStringBuffer.toString();
return result;
}

private String addUnitsToChineseMoenyString(String moneyStr){
String result;
StringBuffer cMoneyStringBuffer=new StringBuffer(moneyStr);

int indexOfDot=cMoneyStringBuffer.indexOf(DOT);
cMoneyStringBuffer.replace(indexOfDot,indexOfDot+1,YUAN);
cMoneyStringBuffer.insert(cMoneyStringBuffer.length()-1,JIAO);
cMoneyStringBuffer.insert(cMoneyStringBuffer.length(),FEN);

//拾佰仟萬億等都是漢字裡面才有的單位,加上它們
if(cMoneyStringBuffer.indexOf("零角零分")!=-1)//去掉零頭,加整
cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零角零分"),
cMoneyStringBuffer.length(),"整");
else if(cMoneyStringBuffer.indexOf("零分")!=-1)//去掉零分,加整
cMoneyStringBuffer.replace(cMoneyStringBuffer.indexOf("零分"),
cMoneyStringBuffer.length(),"整");
else if(cMoneyStringBuffer.indexOf("零角")!=-1)
cMoneyStringBuffer.delete(cMoneyStringBuffer.indexOf("零角"),
cMoneyStringBuffer.indexOf("零角")+2);
result=cMoneyStringBuffer.toString();
return result;
}

//檢查精度的合法性
private void checkPrecision(String moneyStr){
int fractionDigits=moneyStr.length()-moneyStr.indexOf(DOT)-1;
if(fractionDigits>2)//精度不能比分低
throw new RuntimeException("金額"+moneyStr+"的小數位數多餘兩位.");
}

public static void main(String[] args){
System.out.println(getInstance().format(new Double(10010001.01)));
}

}

熱點內容
摩爾庄園腳本容易檢測嗎 發布:2024-11-08 16:54:47 瀏覽:755
易享伺服器地址 發布:2024-11-08 15:55:59 瀏覽:752
愛奇藝的密碼哪裡看 發布:2024-11-08 15:52:45 瀏覽:533
安卓10和平板哪個更流暢 發布:2024-11-08 15:51:18 瀏覽:75
配置低也能玩的槍戰游戲有哪些 發布:2024-11-08 15:41:59 瀏覽:169
python中文匹配 發布:2024-11-08 15:41:06 瀏覽:400
通分新演算法 發布:2024-11-08 15:37:01 瀏覽:370
安卓多樂夠級為什麼沒有捕魚 發布:2024-11-08 15:32:27 瀏覽:657
高級資料庫系統 發布:2024-11-08 15:32:14 瀏覽:540
adovc資料庫 發布:2024-11-08 15:32:11 瀏覽:541