3 Replies Latest reply on Sep 24, 2013 11:46 PM by DenisPlesnar

# Help: number to text (with a twist)

### Title

Help: number to text (with a twist)

### Post

Hi,

First, as a short introduction: I'm from Croatia, and I've been using FileMaker for years, mostly customising ready-made templates and solutions, but I managed to make several relatively complicated solutions which I use regularly - one of those is an invoicing solution.

Recently our local regulations have changed, and now we also need to state the invoice amount in text :(
So, I'm looking for a "number to text" solution - but for Croatian language, which means that I need to adjust and change the available solution, here:

This solution works fine for English language, but, unfortunately, Croatian is a bit more complicated, since different numbers have different endings.

My problem is that I need different endings for different parts of numbers, for Croatian currency (dollar="kuna", and cent="lipa"):

endings for thousands:

1 - tisucA (e.g. 31.000 = "thirty one tisucA")

2, 3, 4 - tisucE (e.g. 22.000 = "twenty two tisucE")

5, 6, 7, 8, 9 - tisucA (e.g. 45.000 = "forty five tisucA"

range from 11.000 to 19.000 is always "tisucA", e.g. 19.000 = "nineteen tisuca"

endings for single digits:

1 - kunA ( e.g. 1 = one kuna)

2,3,4 - kunE (e.g. 23 = twenty three kune)

5,6,7,8,9 - kunA (e.g. 25 = twenty five kuna)

but, for the range from 10 to 20 (i.e. 11-19), the ending is always "kunA", e.g. 13 = "thirteen kuna"

I have already solved the "cents" portion (which in Croatian is "lipa"), as follows:

("TxtPrih_BRU" is the number (amount) field converted to text - in order to use text functions..., formatted as "1234,56" or "1235,00" , where comma is the decimal point, and the function part below operates on the two decimals after the comma)

....

```&
If(Mod(Int(TxtPrih_BRU*10); 10) = 1;
Choose(Mod(Int(TxtPrih_BRU*100); 10); "deset"; "jedanaest"; "dvanaest"; "trinaest"; "četrnaest"; "petnaest"; "šesnaest"; "sedamnaest"; "osamnaest"; "devetnaest");
Choose(Mod(Int(TxtPrih_BRU*10); 10); ""; ""; "dvadeset"; "trideset"; "četrdeset"; "pedeset"; "šezdeset"; "sedamdeset"; "osamdeset"; "devedeset")
&
Choose(Mod(Int(TxtPrih_BRU*100); 10); "nula"; "jedna"; "dvije"; "tri"; "četiri"; "pet"; "šest"; "sedam"; "osam"; "devet"))
&
Case(Right(GetAsText(TxtPrih_BRU); 1) = "0"; " lipa";Right(GetAsText(TxtPrih_BRU); 1) = "2"; " lipe"; Right(GetAsText(TxtPrih_BRU); 1) = "3"; " lipe"; Right(GetAsText(TxtPrih_BRU); 1) = "4"; " lipe"; " lipa")```

That was relatively easy - but now I'm stuck on "dollars" ("kuna") part, and the thousands part (tisuća/tisuće/tisuća  as explained above).

I hope I've explained the problem, and also hope that someone can shed some light on how best to approach this problem...

TIA,

Denis

• ###### 1. Re: Help: number to text (with a twist)

I managed to hack a solution that works (at least it seems so far, with the various test data thrown at it....)

The full solution is too long (and too primitive) to post here, but if anyone's interested, I can post it, anyway.

• ###### 2. Re: Help: number to text (with a twist)

Post the full solution anyway, may be that we can find a less primitive way.

• ###### 3. Re: Help: number to text (with a twist)

Sorry for the very late reply, I forgot to check this thread in a while :(

OK, here it is, in all its primitive glory :)

As stated above, I'm using "TxtPrih_BRU" as the number (amount) field converted to text - in order to use text functions..., formatted as "1234,56" or "1235,00" , where comma is the decimal point.

Here's the full function:

```Choose(Int(Mod(TxtPrih_BRU;10^9) / 10^8); ""; "sto"; "dvjesto"; "tristo"; "četiristo"; "petsto"; "šeststo"; "sedamsto"; "osamsto"; "devetsto") &
If(Int(Mod(TxtPrih_BRU;10^8) / 10^7) = 1;
Choose(Int(Mod(TxtPrih_BRU;10^7) / 10^6); "deset"; "jedanaest"; "dvanaest"; "trinaest"; "četrnaest"; "petnaest"; "šesnaest"; "sedamnaest"; "osamnaest"; "devetnaest");
Choose(Int(Mod(TxtPrih_BRU;10^8) / 10^7); ""; ""; "dvadeset"; "trideset"; "četrdeset"; "pedeset"; "šezdeset"; "sedamdeset"; "osamdeset"; "devedeset") &
Choose(Int(Mod(TxtPrih_BRU;10^7) / 10^6); ""; "jedan"; "dva"; "tri"; "četiri"; "pet"; "šest"; "sedam"; "osam"; "devet"))
&
Case(Int(TxtPrih_BRU) > 10000000 and Int(TxtPrih_BRU) < 20000000; "milijuna";
Int(TxtPrih_BRU) > 1000000 and Int(TxtPrih_BRU) < 2000000; "milijun";
Int(Mod(TxtPrih_BRU;10^9)/10^6) and Int(Mod(TxtPrih_BRU;10^6) / 10^3); "milijuna"; Int(Mod(TxtPrih_BRU;10^9)/10^6);"milijun";"")
&
Choose(Int(Mod(TxtPrih_BRU;10^6) / 10^5); ""; "sto"; "dvjesto"; "tristo"; "četiristo"; "petsto"; "šeststo"; "sedamsto"; "osamsto"; "devetsto")
&
If(Int(Mod(TxtPrih_BRU;10^5) / 10^4) = 1;
Choose(Int(Mod(TxtPrih_BRU;10^4) / 10^3); "deset"; "jedanaest"; "dvanaest"; "trinaest"; "četrnaest"; "petnaest"; "šesnaest"; "sedamnaest"; "osamnaest"; "devetnaest");
Choose(Int(Mod(TxtPrih_BRU;10^5) / 10^4); ""; ""; "dvadeset"; "trideset"; "četrdeset"; "pedeset"; "šezdeset"; "sedamdeset"; "osamdeset"; "devedeset")
&
Choose(Int(Mod(TxtPrih_BRU;10^4) / 10^3); ""; "jedna"; "dvije"; "tri"; "četiri"; "pet"; "šest"; "sedam"; "osam"; "devet"))
&
Case(Int(TxtPrih_BRU) > 10000 and Int(TxtPrih_BRU) < 20000; "tisuća";
Right(Int(Mod(TxtPrih_BRU;10^4) / 10^3);1) = 1; "tisuća";
Right(Int(Mod(TxtPrih_BRU;10^4) / 10^3);1) = 2; "tisuće";
Right(Int(Mod(TxtPrih_BRU;10^4) / 10^3);1) = 3; "tisuće";
Right(Int(Mod(TxtPrih_BRU;10^4) / 10^3);1) = 4; "tisuće";
Right(Int(Mod(TxtPrih_BRU;10^4) / 10^3);1) > 4; "tisuća";
Int(Mod(TxtPrih_BRU;10^6)/10^3) and Int(Mod(TxtPrih_BRU;10^3) / 10^0); "tisuća";"")
&
Choose(Int(Mod(TxtPrih_BRU;10^3) / 100); ""; "sto"; "dvjesto"; "tristo"; "četiristo"; "petsto"; "šeststo"; "sedamsto"; "osamsto"; "devetsto") &
If(Int(Mod(TxtPrih_BRU;100) / 10) = 1;
Choose(Int(Mod(TxtPrih_BRU;10)); "deset"; "jedanaest"; "dvanaest"; "trinaest"; "četrnaest"; "petnaest"; "šesnaest"; "sedamnaest"; "osamnaest"; "devetnaest");
Choose(Int(Mod(TxtPrih_BRU;100) / 10); ""; ""; "dvadeset"; "trideset"; "četrdeset"; "pedeset"; "šezdeset"; "sedamdeset"; "osamdeset"; "devedeset") &
Choose(Int(Mod(TxtPrih_BRU;10)); ""; "jedna"; "dvije"; "tri"; "četiri"; "pet"; "šest"; "sedam"; "osam"; "devet"))
&
Case(Right(Int(TxtPrih_BRU);2) > 10 and Right(Int(TxtPrih_BRU);2) < 20; " kuna i "; Int(TxtPrih_BRU) = 0; "nula kuna i ";
Right(Int(TxtPrih_BRU);1) = 0; " kuna i "; Right(Int(TxtPrih_BRU);1) = 1; " kuna i "; Right(Int(TxtPrih_BRU);1) = 2; " kune i "; Right(Int(TxtPrih_BRU);1) = 3; " kune i "; Right(Int(TxtPrih_BRU);1) = 4; " kune i "; Right(Int(TxtPrih_BRU);1) > 4; " kuna i "; Right(Int(TxtPrih_BRU);3) > 99; " kuna i ";" ")
&
If(Mod(Int(TxtPrih_BRU*10); 10) = 1;
Choose(Mod(Int(TxtPrih_BRU*100); 10); "deset"; "jedanaest"; "dvanaest"; "trinaest"; "četrnaest"; "petnaest"; "šesnaest"; "sedamnaest"; "osamnaest"; "devetnaest");
Choose(Mod(Int(TxtPrih_BRU*10); 10); ""; ""; "dvadeset"; "trideset"; "četrdeset"; "pedeset"; "šezdeset"; "sedamdeset"; "osamdeset"; "devedeset")
&
Choose(Mod(Int(TxtPrih_BRU*100); 10); ""; "jedna"; "dvije"; "tri"; "četiri"; "pet"; "šest"; "sedam"; "osam"; "devet"))
&
Case(Right(GetAsText(TxtPrih_BRU); 2) = "00"; "nula lipa"; Right(GetAsText(TxtPrih_BRU); 1) = "0"; " lipa";Right(GetAsText(TxtPrih_BRU); 1) = "2"; " lipe"; Right(GetAsText(TxtPrih_BRU); 1) = "3"; " lipe"; Right(GetAsText(TxtPrih_BRU); 1) = "4"; " lipe";" lipa")```

Not very elegant, but as they say - hey, it works - at least with all the test data I've tried it with.