如何将数字转换为印度货币格式的单词 [英] How to Convert numbers to word in indian Currency Format

查看:304
本文介绍了如何将数字转换为印度货币格式的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有此字段的pdf表格

I have A pdf form With this field

1.Invoice
2.Date
3.Truck No 
4.Party Name
5.Party Place 
6.City
7.GSTIN
8.Product
9.HSN
10.QTY
11.Rate
12.Amount
13.CGST
14.SGST
15.Total
16.Number

这些是我的表单字段

我需要通过javascript将我的号码转换为单词

I need to Convert My Number to word By javascript

示例:5279.40 =两百七十九和四十派帕斯

Example:5279.40=Two Hundred Seventy-Nine and Forty paise

我要转换字段金额"(这是我的数字字段) 到数字"字段中的数字

I want to Convert field "Amount" (This is my Numeric Field) To Numbers in "Number" Field

我要在"NUmber"字段中输出

I want Output In Field "NUmber"

这是我的Custum验证脚本

This is My Custum Valiation Script

function ConvertToWords(num)
    {
    var aUnits = [ "Thousand", "Million", "Billion", "Trillion", "Quadrillion" ];
    var cWords = "and ";
    // var cWords = (num >= 1 && num < 2) ? "Dollar and " : "Dollars and "; // use for spelled out words
    var nLeft = Math.floor(num);
    for (var i = 0; nLeft > 0; i++) { 
    if (nLeft % 1000 > 0) {
    if (i != 0)
    cWords = ConvertToHundreds(nLeft) + " " + aUnits[i - 1] + " " + cWords;
    else
    cWords = ConvertToHundreds(nLeft) + " " + cWords;
           }
    nLeft = Math.floor(nLeft / 1000);
       }
    num = Math.round(num * 100) ;
    cWords += util.printf("%,102/100 Dollars", num); // numerical cents
    /* for spelled out cents
    if (num > 0) {
    cWords += ConvertToHundreds(num) + " Cents"; // spelled out cents
    } else {
    cWords += "Zero Cents";
        } 
    */
    return cWords;
    }

我正在使用Custum计算脚本

我的Custum计算脚本JavaScript下面

I am using A Custum Calculation Script

Below my Custum Calculation Script JavaScript

        var f = this.getField("Total");

    event.value = ConvertToHundreds(f.value);

但是此脚本不会提供我需要的输出 它不会在Field("Amount")中显示小数后的金额

But this script won't give the Output That I need its does not show the Amount After Decimal in Field("Amount")

如您在F图1.1中所见

As you can see in FFigure 1.1

图1.1

或者此代码还会犯一个错误,您可以在图1.2中看到

or this code does one more Mistake you Can see In Figure 1.2

图1.2 (您可以在数字"字段中看到它仅显示四十但我在金额"字段中的金额为5040.00)

Figure 1.2 ("You Can See In "Number" Field Its only Show Forty But my Amount in "Amount" Field is 5040.00 ")

请给我建议或代码以解决我的问题

Pls give Me suggestion or a code that is Solve My Problem

请不要给我重复我的问题我已经在 https://stackoverflow.com 没有解决方案,也没有代码将数字转换为印度货币的代码,但我发现答案很少,但没有用使用印度货币

Pls dont give me Duplicate of my Question I am Already Search this question on " https://stackoverflow.com" there is no Solution or no Code that Convert Numbers to words In INdian Currency I Found Few of Answer but They Wont work with Indian Currency

推荐答案

我用它来将印度卢比的金额转换为具有派斯价值的单词.基本上,如果我们生成角度为7+或更高的管道,则它与Typescript一起正常工作.有关斜角管道的更多信息,请通过url 斜角7以上的管道

I've used it to convert Indian rupees amount in words with paise value. Basically it works fine with typescript if we generate a pipe in angular 7+ or above. For more information about pipes in angular go through the url pipes in angular 7+ or above

a = [
    '',
    'One ',
    'Two ',
    'Three ',
    'Four ',
    'Five ',
    'Six ',
    'Seven ',
    'Eight ',
    'Nine ',
    'Ten ',
    'Eleven ',
    'Twelve ',
    'Thirteen ',
    'Fourteen ',
    'Fifteen ',
    'Sixteen ',
    'Seventeen ',
    'Eighteen ',
    'Nineteen '];
b = [
    '',
    '',
    'Twenty',
    'Thirty',
    'Forty',
    'Fifty',
    'Sixty',
    'Seventy',
    'Eighty',
    'Ninety'];

transform(value: any): any {
    if (value) {
        let number = parseFloat(value).toFixed(2).split(".")
        let num = parseInt(number[0]);
        let digit = parseInt(number[1]);
        if (num) {
            if ((num.toString()).length > 9)  { return ''; }
            const n = ('000000000' + num).substr(-9).match(/^(\d{2})(\d{2})(\d{2})(\d{1})(\d{2})$/);
            const d = ('00' + digit).substr(-2).match(/^(\d{2})$/);
            if (!n) {return ''; }
            let str = '';
            str += (Number(n[1]) !== 0) ? (this.a[Number(n[1])] || this.b[n[1][0]] + ' ' + this.a[n[1][1]]) + 'Crore ' : '';
            str += (Number(n[2]) !== 0) ? (this.a[Number(n[2])] || this.b[n[2][0]] + ' ' + this.a[n[2][1]]) + 'Lakh ' : '';
            str += (Number(n[3]) !== 0) ? (this.a[Number(n[3])] || this.b[n[3][0]] + ' ' + this.a[n[3][1]]) + 'Thousand ' : '';
            str += (Number(n[4]) !== 0) ? (this.a[Number(n[4])] || this.b[n[4][0]] + ' ' + this.a[n[4][1]]) + 'Hundred ' : '';
            str += (Number(n[5]) !== 0) ? (this.a[Number(n[5])] || this.b[n[5][0]] + ' ' + this.a[n[5][1]]) + 'Rupee ' : '';        
            str += (Number(d[1]) !== 0) ? ((str !== '' ) ? "and " : '') + (this.a[Number(d[1])] || this.b[d[1][0]] + ' ' + this.a[d[1][1]]) + 'Paise Only' : 'Only';
            return str;
        } else {
            return '';
        }
    } else {
        return '';
    }
}

这篇关于如何将数字转换为印度货币格式的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆