# How to format numbers?

[b][red]This message was edited by interpim at 2005-1-10 9:26:20[/red][/b][hr]
OK I made a calculator for an online video game. It works now, but It only shows the value in one denomination per-se. I am wondering how I would go about displaying in each denomination.

as it goes

100 Copper = 1 Silver
100 Silver = 1 Gold
1000 Gold = 1 Platinum

All of my calculations are based off of gold at the moment so if something is say 8 copper it displays .0008

Is there a way I could filter the final number to put it with a P,G,S, and C for each denomination of material?

so if something was 1.3423 Gold have it display 1G 34S 23C ?
or even say 1034.1234 Gold to have it display 1P 34G 12S 34C ?

my program is here if you need an idea of what im talking about
http://interpim.com/SalvageCalc.rar

Thanks all for any input and advice, learning as i go

code below
[code]
Dim metals() As Decimal = {0.0008, 0.0138, 0.0552, 0.1656, 0.4968, 0.9936, 1.4904, 2.2356, 3.3534, 5.0301}
Dim totalmetal As Decimal
Dim total As Decimal
Function ZeroIf(ByVal value As String) As Double
value = value.Trim

If IsNumeric(value) Then
Return CDbl(value)
Else
Return 0
End If
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim matM1 = ZeroIf(TextBox1.Text) * metals(0)
Dim matM2 = ZeroIf(TextBox2.Text) * metals(1)
Dim matM3 = ZeroIf(TextBox4.Text) * metals(2)
Dim matM4 = ZeroIf(TextBox3.Text) * metals(3)
Dim matM5 = ZeroIf(TextBox8.Text) * metals(4)
Dim matM6 = ZeroIf(TextBox7.Text) * metals(5)
Dim matM7 = ZeroIf(TextBox6.Text) * metals(6)
Dim matM8 = ZeroIf(TextBox5.Text) * metals(7)
Dim matM9 = ZeroIf(TextBox10.Text) * metals(8)
Dim matM10 = ZeroIf(TextBox9.Text) * metals(9)

Label20.Text = matM1
Label19.Text = matM2
Label18.Text = matM3
Label17.Text = matM4
Label16.Text = matM5
Label15.Text = matM6
Label14.Text = matM7
Label13.Text = matM8
Label12.Text = matM9
Label11.Text = matM10
Label25.Text = (matM1 + matM2 + matM3 + matM4 + matM5 + matM6 + matM7 + matM8 + matM9 + matM10)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""
TextBox10.Text = ""
Dim mat1 = ZeroIf(TextBox1.Text) * metals(0)
Dim mat2 = ZeroIf(TextBox2.Text) * metals(1)
Dim mat3 = ZeroIf(TextBox4.Text) * metals(2)
Dim mat4 = ZeroIf(TextBox3.Text) * metals(3)
Dim mat5 = ZeroIf(TextBox8.Text) * metals(4)
Dim mat6 = ZeroIf(TextBox7.Text) * metals(5)
Dim mat7 = ZeroIf(TextBox6.Text) * metals(6)
Dim mat8 = ZeroIf(TextBox5.Text) * metals(7)
Dim mat9 = ZeroIf(TextBox10.Text) * metals(8)
Dim mat10 = ZeroIf(TextBox9.Text) * metals(9)
Label20.Text = mat1
Label19.Text = mat2
Label18.Text = mat3
Label17.Text = mat4
Label16.Text = mat5
Label15.Text = mat6
Label14.Text = mat7
Label13.Text = mat8
Label12.Text = mat9
Label11.Text = mat10
Label25.Text = (mat1 + mat2 + mat3 + mat4 + mat5 + mat6 + mat7 + mat8 + mat9 + mat10)
End Sub
[/code]

• I am no good at math but it should be simple as cake. Look up the mod operator and that should help you do it mod out the biggest, mod the second out of remainder etc...

~rlc
• [b][red]This message was edited by interpim at 2005-1-12 18:41:36[/red][/b][hr]
: I am no good at math but it should be simple as cake. Look up the mod operator and that should help you do it mod out the biggest, mod the second out of remainder etc...
:
: ~rlc
:

Edit: I fixed it thanks for the help

• Never had a programming class where you had to make a damn vending machine that gave change huh? Well I should have elaberated a little you need both, the division to get the number... then the mod to reset the total minus the last operation.... like so should work for you, it is a little sloppy since I hate math through. ie you may to change dattypes to larger values maybe uints or decmial ifyour values are large.

[code]
Public Const Plat As Long = 10000000
Public Const Gold As Integer = 10000
Public Const Silver As Integer = 100
Public Const Copper As Integer = 1

Public Sub ConvertCurrency(ByVal v_total As Long)
Dim l_MyTotal As Long = v_total
Dim l_SubTotal As Long
Dim l_plat As Integer
Dim l_gold As Integer
Dim l_silver As Integer
Dim l_copper As Long

'get number of Plat in total
l_plat = l_MyTotal / Plat

'subtract the plat now from the total
l_MyTotal = l_MyTotal Mod Plat

'get number of gold
l_gold = l_MyTotal / Gold

'sub gold
l_MyTotal = l_MyTotal Mod Gold

'get number silver in total
l_silver = l_MyTotal / Silver

'subtract the silver now from the total
l_MyTotal = l_MyTotal Mod Silver

'rest are copper since it is 1
l_copper = l_MyTotal

'set to what ever your output is or make a functin and return the results
Label1.Text = "Plat: " & l_plat
Label2.Text = "Gold: " & l_gold
Label3.Text = "Silver: " & l_silver
Label4.Text = "Copper: " & l_copper

End Sub
[/code]

~rlc
• : Never had a programming class where you had to make a damn vending machine that gave change huh? Well I should have elaberated a little you need both, the division to get the number... then the mod to reset the total minus the last operation.... like so should work for you, it is a little sloppy since I hate math through. ie you may to change dattypes to larger values maybe uints or decmial ifyour values are large.
: ~rlc
:
Never had a programming class ever... teaching myself as I go

Thanks for all the help