金額轉換常用方法

2021-08-24 22:47:56 字數 682 閱讀 6532

不管是做銀行的介面,還是一般支付公司的介面,都會用到一些

相關的介面,一般介面對傳遞的金額都會有相關的要求,一般都是以

分為單位,要轉換其實並不難,但很多情況下就是怕出錯,錢啊!!

所以小心了還得小心,金額中最忌諱的就是double和int的混合運算

了,本機上不出問題,草草測試的後果就不堪設想,使用者的資料千奇

百怪,一不小心就是大問題,我這裡寫了兩個常用的方法,我的想法

是減少運算,盡量是字串操作,減少出錯!僅供參考!

希望在這裡能拋磚引玉!

/*** 將以分為單位的字串轉換為double型別

* @param s

* @return

*/public static double str2double(string s)

/*** 拿取去掉小數點的金額

* @param amount

* @return

*/public static string getamountstr(double amount) ")) else if(amountstr.matches("[0-9]+\\.[0-9]")) else if(amountstr.matches("[0-9]+"))

return transamt.replaceall("^0+", "");

}

C 中數字金額轉換大寫金額方法

的主調函式為convertsum,它的引數是string型別的數字字串。在asp.net中呼叫方式如下 label1.text convertsum 數字字串 其 如下 轉換數字金額主函式 包括小數 數字字串 轉換成中文大寫後的字串或者出錯資訊提示字串 public string convertsu...

java金額轉換

author wu 將乙個數字轉化為金額 public class convertnumber 定義陣列存放位數的大寫 private final static string str modify 轉化整數部分 param tempstring return 返回整數部分 private stati...

delphi 金額轉換

procedure tfmbmzc.bitbtn2click sender tobject 金額轉換 const chnum array 0.9 of string 零 壹 貳 叄 肆 伍 陸 柒 捌 玖 chbit array 0.3 of string 圓 拾 佰 仟 vary,m,d word...