Good morning,
I couldn't find any code on the forum to transform a number into letters, for example:
I enter €990.30 and I get Nine hundred and ninety euros and thirty cents
Thanks to you
number to letter conversion
-
DarkDragon
- Addict

- Posts: 2347
- Joined: Mon Jun 02, 2003 9:16 am
- Location: Germany
- Contact:
Re: number to letter conversion
It is language dependent, do you need it for English only?
bye,
Daniel
Daniel
Re: number to letter conversion
Hello DarkDragon,
I am French and I am looking for an algorithm that I could use in PureBasic but with a French conversion
example 123,45€ gives
Cent vingt trois euros et quarante cinq centimes
I am French and I am looking for an algorithm that I could use in PureBasic but with a French conversion
example 123,45€ gives
Cent vingt trois euros et quarante cinq centimes
-
PurePilish
- User

- Posts: 10
- Joined: Mon Oct 07, 2024 9:15 am
Re: number to letter conversion
Hi, I found this online:
https://devforum.roblox.com/t/coding-ch ... nch/500012
At the bottom of the first post, click on "Here is the answer", and then scroll to the bottom of the first post in that thread where the full code is listed. It's in the Lua language but looks easy to translate to PB. It only does numbers, not currency, but it should be easy to add that feature. Hope this helps.
https://devforum.roblox.com/t/coding-ch ... nch/500012
At the bottom of the first post, click on "Here is the answer", and then scroll to the bottom of the first post in that thread where the full code is listed. It's in the Lua language but looks easy to translate to PB. It only does numbers, not currency, but it should be easy to add that feature. Hope this helps.
- Mindphazer
- Enthusiast

- Posts: 487
- Joined: Mon Sep 10, 2012 10:41 am
- Location: Savoie
Re: number to letter conversion
A little help from ChatGPT :
Code: Select all
Global Dim Unites.s(19)
Unites(0) = "zéro"
Unites(1) = "un"
Unites(2) = "deux"
Unites(3) = "trois"
Unites(4) = "quatre"
Unites(5) = "cinq"
Unites(6) = "six"
Unites(7) = "sept"
Unites(8) = "huit"
Unites(9) = "neuf"
Unites(10) = "dix"
Unites(11) = "onze"
Unites(12) = "douze"
Unites(13) = "treize"
Unites(14) = "quatorze"
Unites(15) = "quinze"
Unites(16) = "seize"
Unites(17) = "dix-sept"
Unites(18) = "dix-huit"
Unites(19) = "dix-neuf"
Global Dim Dizaines.s(10)
Dizaines(2) = "vingt"
Dizaines(3) = "trente"
Dizaines(4) = "quarante"
Dizaines(5) = "cinquante"
Dizaines(6) = "soixante"
Dizaines(7) = "soixante-dix"
Dizaines(8) = "quatre-vingt"
Dizaines(9) = "quatre-vingt-dix"
Procedure.s ConvertirEntierEnMots(Nombre)
Protected Texte.s = ""
If Nombre < 20
Texte = Unites(Nombre)
ElseIf Nombre < 100
Protected Dizaine = Nombre / 10
Protected Unite = Nombre % 10
If Dizaine = 7 Or Dizaine = 9
Texte = Dizaines(Dizaine - 1) + "-" + Unites(10 + Unite)
Else
Texte = Dizaines(Dizaine)
If Unite > 0
Texte + "-" + Unites(Unite)
EndIf
EndIf
ElseIf Nombre < 1000
Protected Centaine = Nombre / 100
Protected Reste = Nombre % 100
If Centaine = 1
Texte = "cent"
Else
Texte = Unites(Centaine) + " cent"
EndIf
If Reste > 0
Texte + " " + ConvertirEntierEnMots(Reste)
EndIf
ElseIf Nombre < 1000000
Protected Mille = Nombre / 1000
Reste = Nombre % 1000
If Mille = 1
Texte = "mille"
Else
Texte = ConvertirEntierEnMots(Mille) + " mille"
EndIf
If Reste > 0
Texte + " " + ConvertirEntierEnMots(Reste)
EndIf
ElseIf Nombre <= 1000000
Protected Million = Nombre / 1000000
Reste = Nombre % 1000000
Texte = ConvertirEntierEnMots(Million) + " million"
If Reste > 0
Texte + " " + ConvertirEntierEnMots(Reste)
EndIf
EndIf
ProcedureReturn Texte
EndProcedure
Procedure.s ConvertirNombreEnMots(Nombre.s)
Protected PartieEntiere.i, PartieDecimale.i
Protected Texte.s = ""
PartieEntiere = Val(StringField(Nombre, 1, "."))
PartieDecimale = Val(StringField(Nombre, 2, "."))
Texte = ConvertirEntierEnMots(PartieEntiere)
If PartieDecimale > 0
Texte + " euros et " + ConvertirEntierEnMots(PartieDecimale) + " centimes"
Else
Texte + " euros "
EndIf
ProcedureReturn Texte
EndProcedure
Define Nombre.s
Nombre = InputRequester("Conversion de nombres", "Entrez un nombre (jusqu'à des millions):", "1234.56")
If Nombre <> ""
MessageRequester("Résultat", ConvertirNombreEnMots(Nombre))
EndIf
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
...and unfortunately... Windows at work...
Re: number to letter conversion
Hello everyone,
I tested the Mindphazer code generated by ChatGpt and it works perfectly. The one from Caronte3D is also perfect for me.
Thank you for your help.
I tested the Mindphazer code generated by ChatGpt and it works perfectly. The one from Caronte3D is also perfect for me.
Thank you for your help.
Re: number to letter conversion
Not mine, only corrected the url posted by Marc56us