JS将货币小写转换为大写

/** 数字金额大写转换(可以处理整数,小数,负数) */
function smalltoBIG(n)
{
    var fraction = ['角', '分'];
    var digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
    var unit = [ ['元', '万', '亿'], ['', '拾', '佰', '仟']  ];
    var head = n < 0? '欠': '';
    n = Math.abs(n);  

    var s = '';  

    for (var i = 0; i < fraction.length; i++)
    {
        s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '');
    }
    s = s || '整';
    n = Math.floor(n);  

    for (var i = 0; i < unit[0].length && n > 0; i++)
    {
        var p = '';
        for (var j = 0; j < unit[1].length && n > 0; j++)
        {
            p = digit[n % 10] + unit[1][j] + p;
            n = Math.floor(n / 10);
        }
        s = p.replace(/(零.)*零$/, '').replace(/^$/, '零')  + unit[0][i] + s;
    }
    return head + s.replace(/(零.)*零元/, '元').replace(/(零.)+/g, '零').replace(/^整$/, '零元整');
}

原文地址:https://www.cnblogs.com/cnliang/p/11698343.html

时间: 2024-10-10 07:20:54

JS将货币小写转换为大写的相关文章

传入一个字符串,已知字符串只由字母组成,将其中的大写字母转换为小写,小写转换为大写,返回转换后的字符串

传入一个字符串,已知字符串只由字母组成,将其中的大写字母转换为小写,小写转换为大写,返回转换后的字符串 如传入:@"GOODgoodSTUDY",返回@"goodGOODstudy" */ - (NSString *)upperExchangeLower:(NSString *)str { NSMutableString *str1=[[NSMutableString alloc] initWithString:str]; for (NSUInteger i=0;

js 金额小写转换为大写

<script> jQuery(document).ready(function () { //当金额文本框失去焦点时,自动将数字转化为大写填充到 大写的文本框中 $("#Amount").blur(function () { var amount = $("#Amount").val(); amount = AmountLtoU(amount); $("#CapitalAmount").val(amount); }); }); fu

Linux_C socket 服务器与客户端交互程序(输入小写转换为大写)

client.c 1 /* interactionSocket/client.c 2 * 实现终端与服务器端的交互式输入输出 3 */ 4 #include <stdio.h> 5 #include <stdlib.h> 6 #include <string.h> 7 #include <unistd.h> 8 #include <sys/types.h> 9 #include <sys/socket.h> 10 #include &

js将人民币金额转换为大写

function upDigit(n) { var fraction = ['角', '分']; var digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']; var unit = [ ['元', '万', '亿'], ['', '拾', '佰', '仟'] ]; var head = n < 0? '欠': ''; n = Math.abs(n); var s = ''; for (var i = 0; i < fractio

C#金额小写转换为大写

//传入需要转换的金额(字符串) public static string MoneyToChinese(string strAmount)     { string functionReturnValue = null; bool IsNegative = false; // 是否是负数 if (strAmount.Trim().Substring(0, 1) == "-")         { // 是负数则先转为正数 strAmount = strAmount.Trim().Re

JS函数实现金额小写转大写

止乎于分享! 1 ///<summery>小写金额转化大写金额</summery> 2 function AmountLtoU(amount) { 3 if (isNaN(amount) || amount >= 1000000000000) return "无效金额!"; //数值最大不超过1万亿 4 var sPrefix = amount < 0 ? "(负)" : ""; //将负号‘-’显示成汉字‘(

浮点数转换为大写货币金额

/** * 浮点数转换为大写货币金额 * * @author Bobby * */ public class ConvertFloatNumToRMBFormat { private static String[] upperCaseArray = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌&

C#:小写金额转换为大写

#region 小写金额转换为大写 public static string CurrToChnNum(double Currnum) { string sResult = ""; if (Math.Abs(Currnum) < 1e-20) return "零圆整"; if (Currnum < 1e-20) sResult = "负"; sResult = sResult + StringToChnNum(Math.Abs(Mat

小写金转换为大写

<body><input type="text" id="txt"/><br/><input type="button" id="ss" value="submit"/><br/><input type="text" id="result"/></body><script typ