• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Need help for number to words in adobe acrobat form

New Here ,
Jul 25, 2018 Jul 25, 2018

Copy link to clipboard

Copied

//This is my code now.

var th = ['', 'thousand', 'million', 'billion', 'trillion'];

var dg = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'];

var tn = ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen'];

var tw = ['twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'];

function toWords(s) {

    s = s.toString();

    s = s.replace(/[\, ]/g, '');

    if (s != parseFloat(s)) return 'not a number';

    var x = s.indexOf('.');

    if (x == -1) x = s.length;

    if (x > 15) return 'too big';

    var n = s.split('');

    var str = '';

    var sk = 0;

    for (var i = 0; i < x; i++) {

        if ((x - i) % 3 == 2) {

            if (n == '1') {

                str += tn[Number(n[i + 1])] + ' ';

                i++;

                sk = 1;

            } else if (n != 0) {

                str += tw[n - 2] + ' ';

                sk = 1;

            }

        } else if (n != 0) {

            str += dg[n] + ' ';

            if ((x - i) % 3 == 0) str += 'hundred ';

            sk = 1;

        }

        if ((x - i) % 3 == 1) {

            if (sk) str += th[(x - i - 1) / 3] + ' ';

            sk = 0;

        }

    }

    if (x != s.length) {

        var y = s.length;

        str += 'AND '+ '/100 ';

        for (var i = x + 1; i < y; i++) str += dg[n] + ' ';

    }

    return str.replace(/\s+/g, ' ');

}

//for 150.23, it shows "one hundred fifty AND /100 two three ", I would like to make it to "one hundred fifty AND 23/100"

//Value s will only have two decimals. Is pre-cuted to two decimals by another function.

//I have been working on it but can't manage to find a solution.

//Help would be very appreciate as I'm beginner in programming.

//Thank you

TOPICS
Acrobat SDK and JavaScript

Views

259

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 26, 2018 Jul 26, 2018

Copy link to clipboard

Copied

LATEST

You can find Number to text converter script on the internet. The JavaScript for this is nearly exactly the same as the Acrobat JavaScript. All you have to do is remove the references to web page elements. I did this for the bank check example (which is exactly what you've described) that can be download (by members) from here:

Search Downloads

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines