我有一个带有此字段的pdf表格
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将我的号码转换为单词
示例:5279.40 =两百七十九和四十派帕斯
我要转换字段“金额”(这是我的数字字段) 到“数字”字段中的数字
我要在“数字”字段中输出
这是我的Custum验证脚本
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计算脚本JavaScript下面
var f = this.getField("Total");
event.value = ConvertToHundreds(f.value);
但是此脚本不会提供我需要的输出 它不会在Field(“ Amount”)中显示小数后的金额
如您在FFigure 1.1中所见
或者此代码还会犯一个错误,您可以在图1.2中看到
Figure 1.2(“您可以在“数字”字段中看到它仅显示40,但是我在“金额”字段中的金额是5040.00”)
请给我建议或代码以解决我的问题
请不要给我重复我的问题我已经在“ https://stackoverflow.com”没有解决方案,也没有代码将数字转换为印度货币,但我发现答案很少,但它们无法使用印度货币
答案 0 :(得分:1)
我用它来将印度卢比的金额转换为具有派斯价值的单词。基本上,如果我们生成角度为7+或更高的管道,则它与Typescript一起正常工作。有关角形管道的更多信息,请通过网址 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 '';
}
}