国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

js將數(shù)字金額轉(zhuǎn)換成中文金額格式

這篇具有很好參考價(jià)值的文章主要介紹了js將數(shù)字金額轉(zhuǎn)換成中文金額格式。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

在開(kāi)發(fā)中我們經(jīng)常會(huì)遇到處理數(shù)字的問(wèn)題,下面介紹一種處理數(shù)字金額轉(zhuǎn)換為中文金額的方式:

我們通常使用三種書(shū)面數(shù)字系統(tǒng):全球使用的阿拉伯?dāng)?shù)字系統(tǒng)和兩種本地?cái)?shù)字系統(tǒng)(繁體、簡(jiǎn)體)。常規(guī)時(shí)我們使用阿拉伯?dāng)?shù)字(1,2,3等),但在某些情況中,如金融中我們會(huì)使用繁體漢字來(lái)書(shū)寫(xiě)數(shù)字,繁體字優(yōu)點(diǎn)是安全且無(wú)法篡改,彌補(bǔ)了阿拉數(shù)字易于修改的問(wèn)題,如在銀行帳戶存儲(chǔ)或支票上使用繁體大寫(xiě)數(shù)字。?

中文大寫(xiě)書(shū)寫(xiě)時(shí)的注意事項(xiàng):

中文大寫(xiě)金額數(shù)字應(yīng)用正楷或行書(shū)填寫(xiě),使用繁體字。如壹、貳、叁、肆、伍、陸、柒、捌、玖、拾、佰、仟、萬(wàn)、億、元、角、分、零、整(正)等字樣。

一、中文大寫(xiě)金額數(shù)字到"元"為止的,在"元"之后,應(yīng)寫(xiě)"整"(或"正")字,在"角"之后,可以不寫(xiě)"整"(或"正")字。

二、中文大寫(xiě)金額數(shù)字前應(yīng)標(biāo)明"人民幣"字樣,大寫(xiě)金額數(shù)字有"分"的,"分"后面不寫(xiě)"整"(或"正")字。

三、大寫(xiě)金額數(shù)字應(yīng)緊接"人民幣"字樣填寫(xiě),不得留有空白。大寫(xiě)金額數(shù)字前未印"人民幣"字樣的,應(yīng)加填"人民幣"三字。在票據(jù)和結(jié)算憑證大寫(xiě)金額欄內(nèi)不得預(yù)印固定的"仟、佰、拾、萬(wàn)、仟、佰、拾、元、角、分"字樣。

四、阿拉伯?dāng)?shù)字小寫(xiě)金額數(shù)字中有"0"時(shí),中文大寫(xiě)應(yīng)按照漢語(yǔ)語(yǔ)言規(guī)律、金額數(shù)字構(gòu)成和防止涂改的要求進(jìn)行書(shū)寫(xiě)。

以下是具體代碼實(shí)現(xiàn):

/**
 * convertCurrencyToChinese - 數(shù)字轉(zhuǎn)成漢字
 * @params num === 要轉(zhuǎn)換的數(shù)字
 * @return 漢字
 * 
*/
function convertCurrencyToChinese(num) { if(!num){ return '零'; } // Constants: const MAXIMUM_NUMBER = 99999999999.99; // Predefine the radix characters and currency symbols for output: const CN_ZERO = "零"; const CN_ONE = "壹"; const CN_TWO = "貳"; const CN_THREE = "叁"; const CN_FOUR = "肆"; const CN_FIVE = "伍"; const CN_SIX = "陸"; const CN_SEVEN = "柒"; const CN_EIGHT = "捌"; const CN_NINE = "玖"; const CN_TEN = "拾"; const CN_HUNDRED = "佰"; const CN_THOUSAND = "仟"; const CN_TEN_THOUSAND = "萬(wàn)"; const CN_HUNDRED_MILLION = "億"; // const CN_SYMBOL = "人民幣"; const CN_DOLLAR = "元"; const CN_TEN_CENT = "角"; const CN_CENT = "分"; const CN_INTEGER = "整"; // Variables: // let integral; // Represent integral part of digit number. // let decimal; // Represent decimal part of digit number. let outputCharacters; // The output result. // let parts; // let digits; // let radices; // let bigRadices; // let decimals; let zeroCount; let i; let p; let d; let quotient; let modulus; let currencyDigits = num; // Validate input string: currencyDigits = currencyDigits.toString(); if (currencyDigits === "") { // alert("Empty input!"); return ""; } if (currencyDigits.match(/[^,.\d]/) != null) { // alert("Invalid characters in the input string!"); return ""; } if ((currencyDigits).match(/^((\d{1,3}(,\d{3})*(.((\d{3},)*\d{1,3}))?)|(\d+(.\d+)?))$/) == null) { // alert("Illegal format of digit number!"); return ""; } // Normalize the format of input digits: currencyDigits = currencyDigits.replace(/,/g, ""); // Remove comma delimiters. currencyDigits = currencyDigits.replace(/^0+/, ""); // Trim zeros at the beginning. // Assert the number is not greater than the maximum number. if (Number(currencyDigits) > MAXIMUM_NUMBER) { // eslint-disable-next-line no-console console.warn("輸入的金額太大,請(qǐng)重新輸入!"); return ""; } // Process the coversion from currency digits to characters: // Separate integral and decimal parts before processing coversion: const parts = currencyDigits.split("."); // eslint-disable-next-line prefer-const let [integral, decimal = ''] = parts; if (parts.length > 1) { // Cut down redundant decimal digits that are after the second. decimal = decimal.substr(0, 2); } // Prepare the characters corresponding to the digits: const digits = [CN_ZERO, CN_ONE, CN_TWO, CN_THREE, CN_FOUR, CN_FIVE, CN_SIX, CN_SEVEN, CN_EIGHT, CN_NINE]; const radices = ["", CN_TEN, CN_HUNDRED, CN_THOUSAND]; const bigRadices = ["", CN_TEN_THOUSAND, CN_HUNDRED_MILLION]; const decimals = [CN_TEN_CENT, CN_CENT]; // Start processing: outputCharacters = ""; // Process integral part if it is larger than 0: if (Number(integral) > 0) { zeroCount = 0; for (i = 0; i < integral.length; i++) { p = integral.length - i - 1; d = integral.substr(i, 1); quotient = p / 4; modulus = p % 4; if (d === "0") { zeroCount++; } else { if (zeroCount > 0) { outputCharacters += digits[0]; } zeroCount = 0; outputCharacters += digits[Number(d)] + radices[modulus]; } if (modulus === 0 && zeroCount < 4) { outputCharacters += bigRadices[quotient]; } } outputCharacters += CN_DOLLAR; } // Process decimal part if there is: if (decimal !== "") { for (i = 0; i < decimal.length; i++) { d = decimal.substr(i, 1); if (d !== "0") { outputCharacters += digits[Number(d)] + decimals[i]; } } } // Confirm and return the final output string: if (outputCharacters === "") { outputCharacters = CN_ZERO + CN_DOLLAR; } if (decimal === "") { outputCharacters += CN_INTEGER; } return outputCharacters || ''; }

以上就是實(shí)現(xiàn)過(guò)程。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-604998.html

到了這里,關(guān)于js將數(shù)字金額轉(zhuǎn)換成中文金額格式的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Java【代碼 16】將word、excel文件轉(zhuǎn)換為pdf格式和將pdf文檔轉(zhuǎn)換為image格式工具類分享(Gitee源碼)aspose轉(zhuǎn)換中文亂碼問(wèn)題處理

    感謝小伙伴兒的分享: ● 不羈 ● 郭中天 整合調(diào)整后的工具類Gitee地址:https://gitee.com/yuanzhengme/java_application_aspose_demo ● WordToPdfUtil用于將word文檔轉(zhuǎn)換為pdf格式的工具類 ● ExcelToPdfUtil用于將excel文檔轉(zhuǎn)換為pdf格式的工具類 ● PdfToImageUtil用于將pdf文檔轉(zhuǎn)換為image格式的工具類

    2024年01月24日
    瀏覽(34)
  • JS實(shí)現(xiàn)阿拉伯?dāng)?shù)字轉(zhuǎn)中文

    這個(gè)函數(shù)首先定義了兩個(gè)數(shù)組,一個(gè)用于存儲(chǔ) 0 到 9 的中文字符,另一個(gè)用于存儲(chǔ)各個(gè)位的單位(如十、百、千等)。然后,它使用一個(gè)循環(huán),從個(gè)位開(kāi)始處理數(shù)字,每次處理一位。如果當(dāng)前位是 0,它會(huì)檢查前一位是否也是 0,如果不是,則在結(jié)果字符串中添加一個(gè) “零”

    2024年02月13日
    瀏覽(27)
  • visual studio代碼解析(注釋)英文換成中文包

    visual studio代碼解析(注釋)英文換成中文包

    前文:我們用visual studio看別人代碼或者看函數(shù)不知道意思的時(shí)候,看官方提示,又是全英文看不懂,這種情況換成中文就會(huì)很大提高代碼書(shū)寫(xiě)效率,大家也可以去看官方文檔是怎么教我們做的https://docs.microsoft.com/zh-cn/dotnet/core/install/localized-intellisense 下載中文包 解壓后得到下

    2024年02月13日
    瀏覽(74)
  • EasyExcel3.0讀(日期、數(shù)字或者自定義格式轉(zhuǎn)換)

    依賴 對(duì)象 test_number.xlsx

    2024年02月09日
    瀏覽(13)
  • jquery 數(shù)字金額轉(zhuǎn)化為大寫(xiě)金額

    示例:money:100 轉(zhuǎn)化為 壹佰元整 //大寫(xiě)金額元幣 function DaXieJinE(money) { ?? ?// 漢字的數(shù)字 ?? ?var cnNums = new Array(\\\'零\\\', \\\'壹\\\', \\\'貳\\\', \\\'叁\\\', \\\'肆\\\', \\\'伍\\\', \\\'陸\\\', \\\'柒\\\', \\\'捌\\\', \\\'玖\\\'); ?? ?// 基本單位 ?? ?var cnIntRadice = new Array(\\\'\\\', \\\'拾\\\', \\\'佰\\\', \\\'仟\\\'); ?? ?// 對(duì)應(yīng)整數(shù)部分?jǐn)U展單位 ?? ?var cnIn

    2024年04月12日
    瀏覽(30)
  • js時(shí)間格式化和轉(zhuǎn)換的方法

    近期在練習(xí)或?qū)戫?xiàng)目時(shí)經(jīng)常會(huì)遇到時(shí)間格式的轉(zhuǎn)換問(wèn)題,今天我就來(lái)總結(jié)一下。 1、將日期轉(zhuǎn)換為指定格式( yyyy-MM-dd hh:mm:ss 等格式) 封裝方法format 也可以為Date原型直接添加format方法 2.將時(shí)間戳轉(zhuǎn)換為年月日的格式 或者獲取到date之后結(jié)合format使用 3.將時(shí)間轉(zhuǎn)換為時(shí)間戳 注

    2024年02月11日
    瀏覽(16)
  • 在js中常見(jiàn)的時(shí)間格式及其轉(zhuǎn)換

    在計(jì)算機(jī)編程中,常見(jiàn)的時(shí)間格式有以下幾種: 1:ISO 8601 格式:國(guó)際標(biāo)準(zhǔn)的日期和時(shí)間表示方法。 格式為 “YYYY-MM-DDTHH:mm:ss.sssZ”,其中 “T” 是日期和時(shí)間的分隔符,“Z” 表示時(shí)區(qū)。 例如,“2023-09-29T12:34:56Z” 表示 2023 年 9 月 29 日 12 時(shí) 34 分 56 秒的時(shí)間點(diǎn)。 2:日期字符

    2024年02月07日
    瀏覽(18)
  • JavaScript 格式化金額

    這是 JavaScript 中格式化金額的最常見(jiàn)方法。 Intl.NumberFormat() 構(gòu)造函數(shù)接受兩個(gè)參數(shù):語(yǔ)言環(huán)境和選項(xiàng)。語(yǔ)言環(huán)境是為其格式化金額的語(yǔ)言和地區(qū)。選項(xiàng)是一組控制金額格式的屬性。例如,可以使用樣式屬性來(lái)指定貨幣的格式,使用貨幣屬性來(lái)指定要將金額格式化為的貨幣。

    2024年02月06日
    瀏覽(365)
  • 【js】時(shí)間和時(shí)間戳轉(zhuǎn)換、日期格式化

    1、時(shí)間戳轉(zhuǎn)換日期方法 (格式:2023-08-17) 2、日期字符串轉(zhuǎn)時(shí)間戳 3、時(shí)間戳轉(zhuǎn)換日期+時(shí)間方法 date:時(shí)間戳數(shù)字(格式:2023-08-17 14:11:01) 4、 獲取日期中文格式

    2024年02月12日
    瀏覽(21)
  • 【Java LocalDateTime】LocalDateTime獲取時(shí)間信息、格式化、轉(zhuǎn)換為數(shù)字時(shí)間戳

    文章目錄 正文 ? ? ? ? 一、描述 ????????二、基本使用 1、獲取LocalDateTime時(shí)間 2、時(shí)間比較 3、獲取基本時(shí)間信息: 4、格式化 /?反格式化 5、轉(zhuǎn)換為數(shù)字時(shí)間戳 6、數(shù)字時(shí)間戳轉(zhuǎn)為L(zhǎng)ocalDateTime ????????LocalDateTime是Java 8引入的日期和時(shí)間API (java.time包)中的一個(gè)類, 不包含

    2024年02月03日
    瀏覽(22)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包