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

Number to German Word

Explorer ,
Aug 13, 2018 Aug 13, 2018

Copy link to clipboard

Copied

Hey,

I need a Function which will convert any given number to the german words like 820 = "achthunderundzwanzig"

I've found an english version which works for e.g. 820 (I made a few changes to represent the german words for the numbers) except if the number contains ones at the end like 825 or 929 then it shows the word like: "neunhundertzwanzigneun" which should be of course "neunhundertneunundzwanzig"

function int_to_words(int) {   if (int === 0) return 'zero';    var ONES  = ['','eins','zwei','drei','vier','fünf','sechs','sieben','acht','neun','zehn','elf','zwölf','dreizehn','vierzehn','fünfzehn','sechzehn','siebzehn','achtzehn','nunzehn'];   var TENS  = ['','','zwanzig','dreizig','vierzig','fünfzig','sechzig','siebzig','achtzig','neunzig'];   var SCALE = ['','tausend','millionen','billionen','trillionen','quadrillionen','quintillionen','sextillionen','septillionen','octillionen','nonillionen'];    // Return string of first three digits, padded with zeros if needed   function get_first(str) {     return ('000' + str).substr(-3);   }    // Return string of digits with first three digits chopped off   function get_rest(str) {     return str.substr(0, str.length - 3);   }    // Return string of triplet convereted to words   function triplet_to_words(_3rd, _2nd, _1st) {     return (_3rd == '0' ? '' : ONES[_3rd] + 'hundert') + (_1st == '0' ? TENS[_2nd] : TENS[_2nd] && TENS[_2nd] + '' || '') + (ONES[_2nd + _1st] || ONES[_1st]);   }    // Add to words, triplet words with scale word   function add_to_words(words, triplet_words, scale_word) {     return triplet_words ? triplet_words + (scale_word && '' + scale_word || '') + '' + words : words;   }    function iter(words, i, first, rest) {     if (first == '000' && rest.length === 0) return words;     return iter(add_to_words(words, triplet_to_words(first[0], first[1], first[2]), SCALE), ++i, get_first(rest), get_rest(rest));   }    return iter('', 0, get_first(String(int)), get_rest(String(int))); }

Can someone show me what I need to change from the script above?

TOPICS
Acrobat SDK and JavaScript , Windows

Views

296

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

correct answers 1 Correct answer

Explorer , Aug 17, 2018 Aug 17, 2018

Votes

Translate

Translate
Explorer ,
Aug 17, 2018 Aug 17, 2018

Copy link to clipboard

Copied

LATEST

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