0

Da numeri a lettere

Mi serviva una funzione per stampare delle ricevute in cifre ed in lettere così anche se non sono un esperto ho scritto una funzione che può essere utile a tutti.

function numtoletter(number) --> result trasforma un importo al di sotto di 100.000  in lettere. Utile per generare delle ricevute con testo in cifre ed in lettere

 

Il codice è posto nelle script globali

function numtoletter(n : number) do
    let x := 0;
    let nVal := 0;
    let cResult := "";
    let cSlash := "/";
    let cNum := format(abs(n), "00000.00");
    let cInt := substring(cNum, 0, 5);
    let cDec := substring(cNum, 6, 8);
    let aQuattro := ["", "uno", "due", "tre", "quattro", "cinque", "sei", "sette", "otto", "nove"];
    let aTre := ["", "dieci", "venti", "trenta", "quaranta", "cinquanta", "sessanta", "settanta", "ottanta", "novanta"];
    let aTreBis := ["", "dic", "vent", "trent", "quarant", "cinquant", "sessant", "settant", "ottant", "novant"];
    let aDue := ["", "cento", "duecento", "trecento", "quattrocento", "cinquecento", "seicento", "settecento", "ottocento", "novecento"];
    let aUno := ["", "mille", "duemila", "tremila", "quattromila", "cinquemila", "seimila", "settemila", "ottomila", "novemila"];
    let aZero := ["", "diecimila", "ventimila", "trentamila", "quarantaomila", "cinquantamila", "sessantamila", "settantamila", "ottantamila", "novantamila"];
    let aExtra := ["", "undici", "dodici", "tredici", "quattordici", "quindici", "sedici", "diciassette", "diciotto", "diciannove"];
    let nExtra := number(substring(cNum, 3, 5));
    let nAbbr := number(substring(cNum, 4, 5));
    let nAbbr2 := number(substring(cNum, 2, 3));
    let lAbbr := false;
    let lExtra := false;
    let lExtra2 := false;
    let nExtra2 := number(substring(cNum, 0, 2));
    if nAbbr = 8 or nAbbr = 1 then
        aTre := aTreBis
    end;
    if nAbbr2 = 8 or nAbbr2 = 1 then
        aZero := aTreBis
    end;
    if nExtra > 10 and nExtra < 20 then
        lExtra := true
    end;
    if nExtra2 > 10 and nExtra2 < 20 then
        lExtra2 := true
    end;
    if n > 99999 then
        "Importo troppo elevato |" + text(n) + "|"
    else
        while x < 5 do 
            nVal := number(substring(cInt, x, x + 1));
            switch x do
            case 4:
                if lExtra then
                    cResult := cResult + item(aExtra, nVal)
                else
                    cResult := cResult + item(aQuattro, nVal)
                end
            case 3:
                if lExtra then
                    cResult := cResult + ""
                else
                    cResult := cResult + item(aTre, nVal)
                end
            case 2:
                (cResult := cResult + item(aDue, nVal))
            case 1:
                if lExtra2 then
                    cResult := cResult + item(aExtra, nVal) + "mila"
                else
                    cResult := cResult + item(aUno, nVal)
                end
            case 0:
                if lExtra2 then
                    cResult := cResult + item(aExtra, nVal)
                else
                    cResult := cResult + item(aZero, nVal)
                end
            default:
                ""
            end;
            x := x + 1;
            if n < 1 then cResult := "zero" end;
            if n < 0 then
                cResult := "NUMERO NEGATIVO"
            end;

 

in allegato un file di esempio di tabella Ninox "assegno.ninox"

1 reply

null
    • Ninox partner
    • RoSoft_Steven.1
    • 1 yr ago
    • Reported - view

    visiolimaurizio

     Grazie per aver condiviso questo.

Content aside

  • 1 yr agoLast active
  • 1Replies
  • 80Views
  • 2 Following