473,383 Members | 1,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

How to Convert Currency or Negative Numbers into Words?

yosiro
34
I have a module to convert numbers (in positive value) into My Language (indonesian) words below:

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2.  
  3. Public Function ubah_terbilang(xbil As Double)
  4.    Dim nilai, i, j, k, hasil$, HasilAkhir$, Bilangan#, Digit, Rp$, Bil$
  5.  
  6.    If IsNull(xbil) Then
  7.       ubah_terbilang = Null
  8.       Exit Function
  9.    End If
  10.  
  11. 'pengelompokan
  12.     Dim Kel$(1 To 6), Angka$(1 To 9), Sat$(1 To 3)
  13.     Kel$(1) = "Biliun "
  14.     Kel$(2) = "Triliun "
  15.     Kel$(3) = "Miliar "
  16.     Kel$(4) = "Juta "
  17.     Kel$(5) = "Ribu "
  18.     Kel$(6) = ""
  19.  
  20. 'data angka
  21.     Angka$(1) = "Satu "
  22.     Angka$(2) = "Dua "
  23.     Angka$(3) = "Tiga "
  24.     Angka$(4) = "Empat "
  25.     Angka$(5) = "Lima "
  26.     Angka$(6) = "Enam "
  27.     Angka$(7) = "Tujuh "
  28.     Angka$(8) = "Delapan "
  29.     Angka$(9) = "Sembilan "
  30.  
  31. 'satuan
  32.     Sat$(1) = "Ratus "
  33.     Sat$(2) = "Puluh "
  34.     Sat$(3) = ""
  35.  
  36. 'mulai
  37.    Bilangan# = Val(xbil)
  38.    HasilAkhir$ = ""
  39.    GoSub HitungHuruf
  40.    If hasil$ <> "" Then
  41.     HasilAkhir$ = hasil$ + "Rupiah"
  42.    End If
  43.  
  44. 'hitung pecahan
  45.    Bilangan# = Fix((Bilangan# - Fix(Bilangan#) + 0.005) * 100#)
  46.    If Bilangan# > 0 Then
  47.       GoSub HitungHuruf
  48.       If hasil$ <> "" Then
  49.         HasilAkhir$ = HasilAkhir$ + " " + hasil$ + "Sen"
  50.       End If
  51.    End If
  52.  
  53. ubah_terbilang = HasilAkhir$
  54. Exit Function
  55.  
  56. HitungHuruf:
  57.     Rp$ = Right$(String$(18, "0") + LTrim$(Str$(Fix(Bilangan#))), 18)
  58.     hasil$ = ""
  59.  
  60.     If Val(Rp$) = 0 Then Return
  61.  
  62. 'blg bulat
  63.    For i = 1 To 6
  64.       Bil$ = Mid$(Rp$, i * 3 - 2, 3)
  65.  
  66.       If Val(Bil$) = 1 And i = 5 Then
  67.          hasil$ = hasil$ + "Seribu "
  68.  
  69.       ElseIf Val(Bil$) <> 0 Then
  70.          For j = 1 To 3
  71.             Digit = Val(Mid$(Bil$, j, 1))
  72.             If j = 2 And Right$(Bil$, 2) = "10" Then
  73.                hasil$ = hasil$ + "Sepuluh "
  74.                Exit For
  75.  
  76.             ElseIf j = 2 And Right$(Bil$, 2) = "11" Then
  77.                hasil$ = hasil$ + "Sebelas "
  78.                Exit For
  79.  
  80.             ElseIf j = 2 And Mid$(Bil$, 2, 1) = "1" Then
  81.                hasil$ = hasil$ + Angka$(Val(Right$(Bil$, 1))) + "Belas "
  82.                Exit For
  83.  
  84.             ElseIf Digit = 1 And j = 1 Then
  85.                hasil$ = hasil$ + "Seratus "
  86.  
  87.             ElseIf Digit <> 0 Then
  88.                hasil$ = hasil$ + Angka$(Digit) + Sat$(j)
  89.  
  90.             End If
  91.          Next
  92.          hasil$ = hasil$ + Kel$(i)
  93.       End If
  94.    Next
  95.    Return
  96. End Function
  97.  
When i type negative numbers, this module not works, example i type -100 the result is empty.

Please help me to modify this module when i type positive or negative value into field, this module can translate it to other field.

Thanks
Sep 18 '15 #1

✓ answered by jforbes

Sure, I put that in there thinking that you are trying to include negative numbers in your display. Just remove line 55 from post #2.

So if you remove the negative notation, what do you expect the function to do when it is passed a negative number? ...How are negative number expressed in your language?

4 2016
jforbes
1,107 Expert 1GB
This should/might be close. You'll have to update line 55 to add whatever is needed to the front or end to signify a negative number:
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4.  
  5.  Public Function ubah_terbilang(xbil As Double)
  6.     Dim nilai, i, j, k, hasil$, HasilAkhir$, Bilangan#, Digit, Rp$, Bil$
  7.  
  8.     If IsNull(xbil) Then
  9.        ubah_terbilang = Null
  10.        Exit Function
  11.     End If
  12.  
  13.  'pengelompokan
  14.      Dim Kel$(1 To 6), Angka$(1 To 9), Sat$(1 To 3)
  15.      Kel$(1) = "Biliun "
  16.      Kel$(2) = "Triliun "
  17.      Kel$(3) = "Miliar "
  18.      Kel$(4) = "Juta "
  19.      Kel$(5) = "Ribu "
  20.      Kel$(6) = ""
  21.  
  22.  'data angka
  23.      Angka$(1) = "Satu "
  24.      Angka$(2) = "Dua "
  25.      Angka$(3) = "Tiga "
  26.      Angka$(4) = "Empat "
  27.      Angka$(5) = "Lima "
  28.      Angka$(6) = "Enam "
  29.      Angka$(7) = "Tujuh "
  30.      Angka$(8) = "Delapan "
  31.      Angka$(9) = "Sembilan "
  32.  
  33.  'satuan
  34.      Sat$(1) = "Ratus "
  35.      Sat$(2) = "Puluh "
  36.      Sat$(3) = ""
  37.  
  38.  'mulai
  39.     Bilangan# = Val(xbil)
  40.     HasilAkhir$ = ""
  41.     GoSub HitungHuruf
  42.     If hasil$ <> "" Then
  43.      HasilAkhir$ = hasil$ + "Rupiah"
  44.     End If
  45.  
  46.  'hitung pecahan
  47.     Bilangan# = Fix((Bilangan# - Fix(Bilangan#) + 0.005) * 100#)
  48.     If Bilangan# > 0 Then
  49.        GoSub HitungHuruf
  50.        If hasil$ <> "" Then
  51.          HasilAkhir$ = HasilAkhir$ + " " + hasil$ + "Sen"
  52.        End If
  53.     End If
  54.  
  55.  If xbil < 0 Then HasilAkhir$ = "Negative " & HasilAkhir$
  56.  ubah_terbilang = HasilAkhir$
  57.  Exit Function
  58.  
  59. HitungHuruf:
  60.      Rp$ = Right$(String$(18, "0") + LTrim$(Str$(Fix(Abs(Bilangan#)))), 18)
  61.      hasil$ = ""
  62.  
  63.      If Val(Rp$) = 0 Then Return
  64.  
  65.  'blg bulat
  66.     For i = 1 To 6
  67.        Bil$ = Mid$(Rp$, i * 3 - 2, 3)
  68.  
  69.        If Val(Bil$) = 1 And i = 5 Then
  70.           hasil$ = hasil$ + "Seribu "
  71.  
  72.        ElseIf Val(Bil$) <> 0 Then
  73.           For j = 1 To 3
  74.              Digit = Val(Mid$(Bil$, j, 1))
  75.              If j = 2 And Right$(Bil$, 2) = "10" Then
  76.                 hasil$ = hasil$ + "Sepuluh "
  77.                 Exit For
  78.  
  79.              ElseIf j = 2 And Right$(Bil$, 2) = "11" Then
  80.                 hasil$ = hasil$ + "Sebelas "
  81.                 Exit For
  82.  
  83.              ElseIf j = 2 And Mid$(Bil$, 2, 1) = "1" Then
  84.                 hasil$ = hasil$ + Angka$(Val(Right$(Bil$, 1))) + "Belas "
  85.                 Exit For
  86.  
  87.              ElseIf Digit = 1 And j = 1 Then
  88.                 hasil$ = hasil$ + "Seratus "
  89.  
  90.              ElseIf Digit <> 0 Then
  91.                 hasil$ = hasil$ + Angka$(Digit) + Sat$(j)
  92.  
  93.              End If
  94.           Next
  95.           hasil$ = hasil$ + Kel$(i)
  96.        End If
  97.     Next
  98.     Return
  99.  End Function
  100.  
Sep 18 '15 #2
yosiro
34
Thanks Jforbes, its work, but the "negative" word is now show in the field, like picture attached, can it be removed?

Sep 19 '15 #3
jforbes
1,107 Expert 1GB
Sure, I put that in there thinking that you are trying to include negative numbers in your display. Just remove line 55 from post #2.

So if you remove the negative notation, what do you expect the function to do when it is passed a negative number? ...How are negative number expressed in your language?
Sep 21 '15 #4
yosiro
34
It's done now. I'm making a receipt from this database. Negative number for debit transaction so I can count each group report with sum function not (group a - group b) because there is no standard function for that. Thanks jforbes
Sep 21 '15 #5

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

Similar topics

7
by: pj | last post by:
Why does M$ Query Analyzer display all numbers as positive, no matter whether they are truly positive or negative ? I am having to cast each column to varchar to find out if there are any...
4
by: Charles A. Lackman | last post by:
Hello, I have some textboxes that are doing addition: Dim AString As Double AString = Convert.ToDouble(TextBox1.Text) - Convert.To(DoubleTextBox2.Text) TextBox3.Text =...
4
by: Bob Bryan | last post by:
I am using a select statement to obtain a result set back with aggregated data. The problem is that I am seeing column data with 11 to 13 digits after the decimal point. I tried using the STR...
2
by: Angus Comber | last post by:
Hello Sorry this really is a newbie question! I am doing some floating point arithmetic and calculating the time difference between two dates. The date values being comparied are actually...
11
by: tlyczko | last post by:
Hello Rob B posted this wonderful code in another thread, http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/c84d8538025980dd/6ead9d5e61be85f0#6ead9d5e61be85f0 I could not...
39
by: Frederick Gotham | last post by:
I have a general idea about how negative number systems work, but I'd appreciate some clarification if anyone would be willing to help me. Let's assume we're working with an 8-Bit signed integer,...
5
by: venkat.yara | last post by:
Hi everybody i am new to this group i want to clarify my doubt that how can i write a program that converts corrency from digits to words is there any function. example if i enter 5430 . output...
20
by: Casey | last post by:
Is there an easy way to use getopt and still allow negative numbers as args? I can easily write a workaround (pre-process the tail end of the arguments, stripping off any non-options including...
2
vivek kushwaha
by: vivek kushwaha | last post by:
Hi guys, I need codes to convert Currency into Words. e.g. 120,500 into "One Lac. Five hundred only." in asp.net with vb.net 1.1. Please if anybody know about it. Reply me. Vivek.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.