# B4J QuestionFor computers we have KB, MB, GB, TB etc, for money?

#### Mashiane

##### Expert
Hi

I need something to convert money figures to their equivalents just like one would convert sizes to MB etc.

Is there a general rule across the board for doing this. For example, \$53,447,890.00, would be \$53M.

Thanks

#### thetahsk

##### Active Member
• Mashiane

#### emexes

##### Expert
Typed on phone so no guarantee, but try:
B4X:
``````Sub NumberSuffix(N As Double) As String

If N < 0 Then
Return "-" & NumberSuffix(-N)
End If

Dim Suffix() As String = Array As String("", "k", "M", "B", "T")
'''Dim Suffix() As String = Array As String("", " Thousand", " Million", " Billion", " Trillion")

Dim Thousands As Int = 0
Do While N >= 1000 And Thousands < Suffix.Length - 1
Thousands = Thousands + 1
N = N / 1000
Loop

If Thousands = 0 Then
'2 decimal places per example of monetary amount including cents
Return NumberFormat2(N, 1, 2, 2, False)
End If

'sufficient decimal places for precision required
Dim MaxDecimalPlaces As Int = 0
Do While MaxDecimalPlaces < 5    'absolute maximum 5 decimal places
Dim RelativeError As Double = Abs(N - Round2(N, MaxDecimalPlaces)) / N
If RelativeError < 0.007 Then    'eg 0.7% (or whatever precision you need)
Exit
End If
MaxDecimalPlaces = MaxDecimalPlaces + 1
Loop

Return NumberFormat2(N, 1, 0, MaxDecimalPlaces, False) & Suffix(Thousands)

End Sub``````

Last edited:
• Mashiane

##### Active Member
In this link, https://en.wikipedia.org/wiki/Metric_prefix, at the "Non-metric" paragraph:

"They are also occasionally used with currency units (e.g., gigadollar), mainly by people who are familiar with the prefixes from scientific usage"

#### emexes

##### Expert
I need something to convert money figures to their equivalents just like one would convert sizes to MB etc.
Is there a general rule across the board for doing this. For example, \$53,447,890.00, would be \$53M.
Looks like you might also be headed towards something like this:
B4X:
``````For Each N In Array As Int(53447890, 53447090, 53440090, 53400090, 53000090)
Log(N & " is: " & NumberToWords(N))
Next``````
B4X:
``````53447890 is: Fifty-Three Million, Four Hundred and Forty-Seven Thousand, Eight Hundred and Ninety
53447090 is: Fifty-Three Million, Four Hundred and Forty-Seven Thousand and Ninety
53440090 is: Fifty-Three Million, Four Hundred and Forty Thousand and Ninety
53400090 is: Fifty-Three Million, Four Hundred Thousand and Ninety
53000090 is: Fifty-Three Million and Ninety``````
in which case check out this post (sample) and the one after it (code):

Last edited:
• Mashiane

Replies
15
Views
4K
Replies
0
Views
1K
Replies
2
Views
842
Replies
1
Views
597
B4J Question parse joson google map
Replies
1
Views
816