用vue将数字转为中文大写金额

记得引入vue.js文件

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用vue将数字转为中文大写金额</title>
    <script src=‘vue.js‘></script>
</head>
<body>
    <div id="box">
        <h1 v-if=‘flag‘>我已经限制长度了,放弃吧</h1>
        <h1 v-if=‘flag‘><button @click=‘shutDown‘>关闭</button></h1>
        <input type="text" v-model=‘inputVal‘>
        <!--<button @click=‘to_ch‘>转换</button>-->
        {{inputVal | toChies}}
        <!--过滤器-->
    </div>
</body>
    <script>
        var app = new Vue({
            el:"#box",
            data:{
                inputVal:‘‘,
                flag:false,
                values:‘‘
            },
            filters:{//局部过滤器

                toChies:function(values){//形参
                    let len=values.length//统计出长度
                    let arr=[];

                    let chin_list=[‘零‘,‘壹‘,‘贰‘,‘叁‘,‘肆‘,‘伍‘,‘陆‘,‘柒‘,‘捌‘,‘玖‘]//所有的数值对应的汉字

                    let chin_lisp=[‘仟‘,‘佰‘,‘拾‘,‘亿‘,‘仟‘,‘佰‘,‘拾‘,‘万‘,‘仟‘,‘佰‘,‘拾‘]//进制

                    for(let i=0;i<len;i++){
                        arr.push(parseInt(values[i]));        //输入的数据按下标存进去   存进去的只是数字
                        arr[i]=chin_list[arr[i]]            //是根据我们输入的输入的数字,对应着我们的chin_list这个数组
                    }//123[‘壹‘,‘佰‘,‘贰‘,‘拾‘,‘叁‘]

                    for(let i=len-1,j=1;i>0;i--){//i =2    1        //倒序        为了添加进制,方便我们去观看
                        arr.splice(i,0,chin_lisp[chin_lisp.length-j++])    //j=2
                    }
                    console.log(arr)

                    arr=arr.join(‘‘)
                    if(len>=1){
                        arr+=‘元整‘
                    }
                    return arr
                }

            },
            watch:{
                inputVal(newVal,oldVal){
                    if(newVal.length==13){
                        this.inputVal=oldVal
                        this.flag=true
                    }
                }
            },
            methods:{
                shutDown(){
                    this.flag=false
                },
                to_ch(){
                    console.log(this.inputVal)
                    this.inputVal=this.values
                }
            }
        })
    </script>
</html>

原文地址:https://www.cnblogs.com/qishiwei/p/10453051.html

时间: 2024-07-30 15:28:31

用vue将数字转为中文大写金额的相关文章

利用bootbox.js写二次确认提交(以及数字转为中文数字)

页面文件 <#-- 页头 --> <#assign currNav = "deposit"> <#assign title="网校充值"> <#include "/root/commons/header.ftl"> <div class="container"> <form id="depositForm" name="deposi

将int数字转为中文字符串

1 function int_to_cnstr($intval) { 2 $cnNum = array('零','一','二','三','四','五','六','七','八','九'); 3 $cnUnit = array('','十','百','千','万','亿'); 4 $reCnStr = ''; 5 $intval = intval($intval); 6 if ($intval < 10 && $intval >= 0) { 7 $reCnStr .= $cnNum

PHP 数字金额转换成中文大写金额的函数 数字转中文

/** *数字金额转换成中文大写金额的函数 *String Int $num 要转换的小写数字或小写字符串 *return 大写字母 *小数位为两位 **/ function num_to_rmb($num){ $c1 = "零壹贰叁肆伍陆柒捌玖"; $c2 = "分角元拾佰仟万拾佰仟亿"; //精确到分后面就不要了,所以只留两个小数位 $num = round($num, 2); //将数字转化为整数 $num = $num * 100; if (strlen($

.Net C# 阿拉伯数字转为中文金额数字

一个练习,将阿拉伯数字转为中文金额数字 代码: public string ReturnStr(string inputNum) { string[] intArr = { "0" ,"1", "2", "3", "4", "5", "6", "7", "8", "9", }; string[] strArr

数字转中文,大写,金额

最近,又发现了另外一种数字转中文,大写,金额的方法,觉得会比之前找到的跟合适一点:npm安装包地址:https://npm.taobao.org/package/nzh(在这里,会有更加详细的使用介绍.而我就只是测了其中一种......) 简介:Nzh适用于开发过程中需要将数字转换为中文的场景 以字符串的方式转换,解决超大数及浮点数等问题,请自行对原数据进行四舍五入等操作. 1.首先在项目中安装依赖包:npm install nzh 2.其实这是自己在做小测试的时候,使用nzh的,在安装完依赖包

在C#中将金额转换成中文大写金额

具体代码如下: /// <summary> /// 金额转换成中文大写金额 /// </summary> /// <param name="LowerMoney">eg:10.74</param> /// <returns></returns> public static string MoneyToUpper(string LowerMoney) { string functionReturnValue = nu

【Java】将数字转为汉字(中国钱币-数字转汉字)

今天做了一个题,需要把数字转为汉字,想了一段时间没有结果,于是在网上搜索出了如下方法: 1 package com.b510.number2char; 2 3 import java.math.BigDecimal; 4 5 /** 6 * 数字转换为汉语中人民币的大写<br> 7 * 8 * @author hongten 9 * @contact [email protected] 10 * @create 2013-08-13 11 */ 12 public class NumberTo

PHP中数字转为百分位,千分位,万分位。。。

今天做项目中,需要将文章点击量显示在页面中,需求中给的是多少多少万,虽然不是什么难事,但做程序员这么久了,需要考虑的不再是简单的实现,而且有效率和快捷, 虽然PHP自带的函数有number_format()可以做到实现千分位,但我要的是万分位, 通过查找,发现了可以用以下这个方法: $num = 86231; # 将数字转为万分位 echo $num>10000?sprintf("%.1f", $num/10000):$num; 类似的通过这个方法,可以稍微修改下,就可以实现百分

【OBJC】数字转中文大写

博客园都不知道怎么外链图片…… - (void)numToString:(double)num{ int iLen,iNum,iAddZero=0; NSMutableString *szChMoney = [[NSMutableString alloc] init]; NSArray *hzUnit = @[@"分",@"角",@"元",@"拾",@"佰",@"仟",@"万&