473,608 Members | 2,479 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Converting numbers to Words

missinglinq
3,532 Recognized Expert Specialist
From the Access Object Dialog Box click on "Modules"
Click on new to make a new module
Copy then paste the following code into the new module:

Expand|Select|Wrap|Line Numbers
  1. Function SayNo(ByVal N As Currency) As String
  2.  
  3.     Const Thousand = 1000@
  4.     Const Million = Thousand * Thousand
  5.     Const Billion = Thousand * Million
  6.     Const Trillion = Thousand * Billion
  7.  
  8.     If (N = 0@) Then SayNo = "zero": Exit Function
  9.  
  10.     Dim Buf As String: If (N < 0@) Then Buf = "negative " Else Buf = ""
  11.     Dim Frac As Currency: Frac = Abs(N - Fix(N))
  12.     If (N < 0@ Or Frac <> 0@) Then N = Abs(Fix(N))
  13.     Dim AtLeastOne As Integer: AtLeastOne = N >= 1
  14.  
  15.     If (N >= Trillion) Then
  16.         Debug.Print N
  17.         Buf = Buf & SayNoDigitGroup(Int(N / Trillion)) & " trillion"
  18.         N = N - Int(N / Trillion) * Trillion
  19.         If (N >= 1@) Then Buf = Buf & " "
  20.     End If
  21.  
  22.     If (N >= Billion) Then
  23.         Debug.Print N
  24.         Buf = Buf & SayNoDigitGroup(Int(N / Billion)) & " billion"
  25.         N = N - Int(N / Billion) * Billion
  26.         If (N >= 1@) Then Buf = Buf & " "
  27.     End If
  28.  
  29.     If (N >= Million) Then
  30.         Debug.Print N
  31.         Buf = Buf & SayNoDigitGroup(N \ Million) & " million"
  32.         N = N Mod Million
  33.         If (N >= 1@) Then Buf = Buf & " "
  34.     End If
  35.  
  36.     If (N >= Thousand) Then
  37.         Debug.Print N
  38.         Buf = Buf & SayNoDigitGroup(N \ Thousand) & " thousand"
  39.         N = N Mod Thousand
  40.         If (N >= 1@) Then Buf = Buf & " "
  41.     End If
  42.  
  43.     If (N >= 1@) Then
  44.         Debug.Print N
  45.         Buf = Buf & SayNoDigitGroup(N)
  46.     End If
  47.  
  48.     If (Frac = 0@) Then
  49.         Buf = Buf
  50.     ElseIf (Int(Frac * 100@) = Frac * 100@) Then
  51.         If AtLeastOne Then Buf = Buf & " and "
  52.         Buf = Buf & Format$(Frac * 100@, "00") & "/100"
  53.     Else
  54.         If AtLeastOne Then Buf = Buf & " and "
  55.         Buf = Buf & Format$(Frac * 10000@, "0000") & "/10000"
  56.     End If
  57.  
  58.     SayNo = Buf
  59. End Function
  60.  
  61. Private Function SayNoDigitGroup(ByVal N As Integer) As String
  62.  
  63.     Const Hundred = " hundred"
  64.     Const One = "one"
  65.     Const Two = "two"
  66.     Const Three = "three"
  67.     Const Four = "four"
  68.     Const Five = "five"
  69.     Const Six = "six"
  70.     Const Seven = "seven"
  71.     Const Eight = "eight"
  72.     Const Nine = "nine"
  73.     Dim Buf As String: Buf = ""
  74.     Dim Flag As Integer: Flag = False
  75.  
  76.     Select Case (N \ 100)
  77.         Case 0: Buf = "": Flag = False
  78.         Case 1: Buf = One & Hundred: Flag = True
  79.         Case 2: Buf = Two & Hundred: Flag = True
  80.         Case 3: Buf = Three & Hundred: Flag = True
  81.         Case 4: Buf = Four & Hundred: Flag = True
  82.         Case 5: Buf = Five & Hundred: Flag = True
  83.         Case 6: Buf = Six & Hundred: Flag = True
  84.         Case 7: Buf = Seven & Hundred: Flag = True
  85.         Case 8: Buf = Eight & Hundred: Flag = True
  86.         Case 9: Buf = Nine & Hundred: Flag = True
  87.     End Select
  88.  
  89.     If (Flag <> False) Then N = N Mod 100
  90.     If (N > 0) Then
  91.         If (Flag <> False) Then Buf = Buf & " "
  92.     Else
  93.         SayNoDigitGroup = Buf
  94.         Exit Function
  95.     End If
  96.  
  97.     Select Case (N \ 10)
  98.         Case 0, 1: Flag = False
  99.         Case 2: Buf = Buf & "twenty": Flag = True
  100.         Case 3: Buf = Buf & "thirty": Flag = True
  101.         Case 4: Buf = Buf & "forty": Flag = True
  102.         Case 5: Buf = Buf & "fifty": Flag = True
  103.         Case 6: Buf = Buf & "sixty": Flag = True
  104.         Case 7: Buf = Buf & "seventy": Flag = True
  105.         Case 8: Buf = Buf & "eighty": Flag = True
  106.         Case 9: Buf = Buf & "ninety": Flag = True
  107.     End Select
  108.  
  109.     If (Flag <> False) Then N = N Mod 10
  110.     If (N > 0) Then
  111.         If (Flag <> False) Then Buf = Buf & "-"
  112.     Else
  113.         SayNoDigitGroup = Buf
  114.         Exit Function
  115.     End If
  116.  
  117.     Select Case (N)
  118.         Case 0:
  119.         Case 1: Buf = Buf & One
  120.         Case 2: Buf = Buf & Two
  121.         Case 3: Buf = Buf & Three
  122.         Case 4: Buf = Buf & Four
  123.         Case 5: Buf = Buf & Five
  124.         Case 6: Buf = Buf & Six
  125.         Case 7: Buf = Buf & Seven
  126.         Case 8: Buf = Buf & Eight
  127.         Case 9: Buf = Buf & Nine
  128.         Case 10: Buf = Buf & "ten"
  129.         Case 11: Buf = Buf & "eleven"
  130.         Case 12: Buf = Buf & "twelve"
  131.         Case 13: Buf = Buf & "thirteen"
  132.         Case 14: Buf = Buf & "fourteen"
  133.         Case 15: Buf = Buf & "fifteen"
  134.         Case 16: Buf = Buf & "sixteen"
  135.         Case 17: Buf = Buf & "seventeen"
  136.         Case 18: Buf = Buf & "eighteen"
  137.         Case 19: Buf = Buf & "nineteen"
  138.     End Select
  139.  
  140.     SayNoDigitGroup = Buf
  141.  
  142. End Function
  143.  
Save the module and call it, say, NumbersToWords

Now from your form call the function using the syntax

SayNo(YourNumer icalValue)

As an example (since I don't know your skill level, sorry) here's what I did to test it. After doing the above to create the module, I ran up a simple form with a textbox and a label; txtTextNumbers and lblTextWords

Expand|Select|Wrap|Line Numbers
  1. Private Sub txtTextNumbers_Exit(Cancel As Integer)
  2.      Me.lblTextWords.Caption = SayNo(Me.txtTextNumbers.Value)
  3. End Sub
  4.  
After entering your data and exiting the textbox the label will contain the word equivelent of the number entered.

The same code can be used in other events, of course.

The author is only known to me as M8KWR.
Jan 30 '07 #1
1 21545
puppydogbuddy
1,923 Recognized Expert Top Contributor
See also this link:

http://www.fabalou.com/Access/Modules/numbertowords.asp
Aug 11 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
5383
by: fo | last post by:
Does anyone know if there is a free code available to convert numbers to text and/or text to numbers? Thanks
25
6680
by: TK | last post by:
I'm used to programming in c or c++ in which my problem is simple. I want to be able to enter a value on a page (like 3.2), and then read it as a 32-bit float and break it into it's individual bytes. I've tried using bitwise operators, but they seem to convert the value into an integer first, and i've tried using the toString() method to convert it into a hex value so i can parse it, but that also seems to first convert it into an...
7
3040
by: Converting Numeric to a word | last post by:
Hi, I have little experience in C#, Can anyone help me with this sproblem. " I want to convert a given number in a text to a word on a lable" for eg if we type 25 in text box , i want to display it as 'Twenty Five' on a lable. pls send any related code sample.
7
3592
by: MeganTSU | last post by:
Hey yall! I am trying to get this program finished for class.... It says that you are suppposed to write a program that will display a check formatted out put (the output looks like a check). I got everything to work and it will compile and run...... BUT.... I dont know how to turn the 'Amount' into a charater string that puts the number into words.... It is supposed to show the name, then the amount, and then on the next line write out...
3
4932
by: bolly | last post by:
Hi, I've been putting Python data into a sqlite3 database as tuples but when I retrieve them they come back as unicode data e.g 'u(1,2,3,4)'.How can I change it back to a tuple so I can use it as a Python native datatype? I have looked in the docs and seen there is a decode/encode method but how do I do this? Hope you can help.
2
2077
by: Rohit111111 | last post by:
Hello all, I want to convert number into there equivalent words like if number is 567342 than result is Five Lac sixty seven thousand three hundred and fourty two. I am using asp.net c# Thanks in adv. Rohit Vyas
5
3287
by: lim4801 | last post by:
I am currently in doing a program which is given by my tutor: Contemplate that you are working for the phone company and want to sell "special" phone numbers to companies. These phone numbers are "special" because they are easily translated into words. You've been asked to create a list of phone numbers that are directly mappable to words by searching a dictionary for every 7 or 10 letter word that maps on to the phone lettering scheme: ...
5
1958
by: byte8bits | last post by:
Here's how I'm doing this right now, It's a bit slow. I've just got the code working. I was wondering if there is a more efficient way of doing this... simple example from interactive Python: .... char = unichr(int(h, 16)) .... word += char .... print char .... B r
0
3330
by: Terry Reedy | last post by:
A. Joseph wrote: These are number representation systems that can be applied to or used with integral, rational (numberator,denominator), and 'point' numbers. Try Wikipedia or any search engine. There are standard algorithms for converting between representations. See above. Good programmer calculators have these built in.
3
29155
by: Bouzy | last post by:
I have a list of words and am trying to replace all the numbers in my list with whitespace. for word in words: numbers = re.search('+', word) word = clearup(word) if word in dictionary: pass else: print word
0
8059
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8000
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8495
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8145
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8330
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5475
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3960
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2474
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1328
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.